blob: 0668797386e1d150341905d12ebabccdf2abeb87 [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()
401 CheckDefAndScriptFailure2(['ch_getjob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument:')
402 CheckDefAndScriptFailure2(['ch_getjob({"a": 10})'], 'E1013: Argument 1: type mismatch, expected channel but got dict<number>', 'E731: Using a Dictionary as a String')
403 assert_equal(0, ch_getjob(test_null_channel()))
404enddef
405
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200406def Test_ch_info()
407 if !has('channel')
408 CheckFeature channel
409 endif
410 CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>')
411enddef
412
Bram Moolenaarc5809432021-03-27 21:23:30 +0100413def Test_ch_logfile()
Bram Moolenaar886e5e72021-04-05 13:36:34 +0200414 if !has('channel')
415 CheckFeature channel
416 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200417 assert_fails('ch_logfile(true)', 'E1174:')
418 assert_fails('ch_logfile("foo", true)', 'E1174:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200419
420 CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
421 CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2')
422enddef
423
424def Test_ch_open()
425 if !has('channel')
426 CheckFeature channel
427 endif
428 CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
429 CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100430enddef
431
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200432def Test_ch_read()
433 if !has('channel')
434 CheckFeature channel
435 endif
436 CheckDefAndScriptFailure2(['ch_read(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
437 CheckDefAndScriptFailure2(['ch_read(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
438enddef
439
440def Test_ch_readblob()
441 if !has('channel')
442 CheckFeature channel
443 endif
444 CheckDefAndScriptFailure2(['ch_readblob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
445 CheckDefAndScriptFailure2(['ch_readblob(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
446enddef
447
448def Test_ch_readraw()
449 if !has('channel')
450 CheckFeature channel
451 endif
452 CheckDefAndScriptFailure2(['ch_readraw(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
453 CheckDefAndScriptFailure2(['ch_readraw(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
454enddef
455
456def Test_ch_setoptions()
457 if !has('channel')
458 CheckFeature channel
459 endif
460 CheckDefAndScriptFailure2(['ch_setoptions(1, {})'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
461 CheckDefFailure(['ch_setoptions(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>')
462enddef
463
464def Test_ch_status()
465 if !has('channel')
466 CheckFeature channel
467 endif
468 CheckDefAndScriptFailure2(['ch_status(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
469 CheckDefAndScriptFailure2(['ch_status(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
470enddef
471
Bram Moolenaar94738d82020-10-21 14:25:07 +0200472def Test_char2nr()
473 char2nr('あ', true)->assert_equal(12354)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100474
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200475 assert_fails('char2nr(true)', 'E1174:')
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +0200476 CheckDefAndScriptFailure2(['char2nr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
477 CheckDefAndScriptFailure2(['char2nr("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
478 assert_equal(97, char2nr('a', 1))
479 assert_equal(97, char2nr('a', 0))
480 assert_equal(97, char2nr('a', true))
481 assert_equal(97, char2nr('a', false))
Bram Moolenaarc5809432021-03-27 21:23:30 +0100482enddef
483
484def Test_charclass()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200485 assert_fails('charclass(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100486enddef
487
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200488def Test_charcol()
489 CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
490 CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200491 new
492 setline(1, ['abcdefgh'])
493 cursor(1, 4)
494 assert_equal(4, charcol('.'))
495 assert_equal(9, charcol([1, '$']))
496 assert_equal(0, charcol([10, '$']))
497 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200498enddef
499
500def Test_charidx()
501 CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string')
502 CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
503 CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string')
504enddef
505
Bram Moolenaarc5809432021-03-27 21:23:30 +0100506def Test_chdir()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200507 assert_fails('chdir(true)', 'E1174:')
508enddef
509
510def Test_cindent()
511 CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
512 CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
513 assert_equal(-1, cindent(0))
514 assert_equal(0, cindent('.'))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200515enddef
516
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200517def Test_clearmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200518 CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200519enddef
520
Bram Moolenaar94738d82020-10-21 14:25:07 +0200521def Test_col()
522 new
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200523 setline(1, 'abcdefgh')
524 cursor(1, 4)
525 assert_equal(4, col('.'))
526 col([1, '$'])->assert_equal(9)
527 assert_equal(0, col([10, '$']))
Bram Moolenaarc5809432021-03-27 21:23:30 +0100528
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200529 assert_fails('col(true)', 'E1174:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200530
531 CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
532 CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
533 CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
534 bw!
Bram Moolenaarc5809432021-03-27 21:23:30 +0100535enddef
536
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200537def Test_complete_info()
538 CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
539 CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>')
540 assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info())
541 assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items']))
542enddef
543
Bram Moolenaarc5809432021-03-27 21:23:30 +0100544def Test_confirm()
545 if !has('dialog_con') && !has('dialog_gui')
546 CheckFeature dialog_con
547 endif
548
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200549 assert_fails('confirm(true)', 'E1174:')
550 assert_fails('confirm("yes", true)', 'E1174:')
551 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:')
552enddef
553
Bram Moolenaar94738d82020-10-21 14:25:07 +0200554def Test_copy_return_type()
555 var l = copy([1, 2, 3])
556 var res = 0
557 for n in l
558 res += n
559 endfor
560 res->assert_equal(6)
561
562 var dl = deepcopy([1, 2, 3])
563 res = 0
564 for n in dl
565 res += n
566 endfor
567 res->assert_equal(6)
568
569 dl = deepcopy([1, 2, 3], true)
570enddef
571
572def Test_count()
573 count('ABC ABC ABC', 'b', true)->assert_equal(3)
574 count('ABC ABC ABC', 'b', false)->assert_equal(0)
575enddef
576
Bram Moolenaar9a963372020-12-21 21:58:46 +0100577def Test_cursor()
578 new
579 setline(1, range(4))
580 cursor(2, 1)
581 assert_equal(2, getcurpos()[1])
582 cursor('$', 1)
583 assert_equal(4, getcurpos()[1])
584
585 var lines =<< trim END
586 cursor('2', 1)
587 END
Bram Moolenaar0f1227f2021-07-11 16:01:58 +0200588 CheckDefExecAndScriptFailure(lines, 'E1209:')
Bram Moolenaar9a963372020-12-21 21:58:46 +0100589enddef
590
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200591def Test_debugbreak()
592 CheckMSWindows
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200593 CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200594enddef
595
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100596def Test_delete()
597 var res: bool = delete('doesnotexist')
598 assert_equal(true, res)
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200599
600 CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
601 CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100602enddef
603
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200604def Test_diff_filler()
605 CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
606 CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
607 assert_equal(0, diff_filler(1))
608 assert_equal(0, diff_filler('.'))
609enddef
610
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +0200611def Test_diff_hlID()
612 CheckDefAndScriptFailure2(['diff_hlID(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
613 CheckDefAndScriptFailure2(['diff_hlID(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
614enddef
615
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200616def Test_echoraw()
617 CheckDefAndScriptFailure2(['echoraw(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
618 CheckDefAndScriptFailure2(['echoraw(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
619enddef
620
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200621def Test_escape()
622 CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
623 CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number')
624 CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
625 assert_equal('a\:b', escape("a:b", ":"))
626enddef
627
628def Test_eval()
629 CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
630 CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
631 assert_equal(2, eval('1 + 1'))
632enddef
633
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100634def Test_executable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100635 assert_false(executable(""))
636 assert_false(executable(test_null_string()))
637
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200638 CheckDefExecFailure(['echo executable(123)'], 'E1013:')
639 CheckDefExecFailure(['echo executable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100640enddef
641
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200642def Test_execute()
643 var res = execute("echo 'hello'")
644 assert_equal("\nhello", res)
645 res = execute(["echo 'here'", "echo 'there'"])
646 assert_equal("\nhere\nthere", res)
647
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200648 CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
649 CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200650 CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200651 CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200652enddef
653
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100654def Test_exepath()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200655 CheckDefExecFailure(['echo exepath(true)'], 'E1013:')
656 CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100657 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100658enddef
659
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200660def Test_exists()
661 CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
662 call assert_equal(1, exists('&tabstop'))
663enddef
664
Bram Moolenaar94738d82020-10-21 14:25:07 +0200665def Test_expand()
666 split SomeFile
667 expand('%', true, true)->assert_equal(['SomeFile'])
668 close
669enddef
670
Bram Moolenaar02795102021-05-03 21:40:26 +0200671def Test_expandcmd()
672 $FOO = "blue"
673 assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
674
675 assert_equal("yes", expandcmd("`={a: 'yes'}['a']`"))
676enddef
677
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100678def Test_extend_arg_types()
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100679 g:number_one = 1
680 g:string_keep = 'keep'
681 var lines =<< trim END
682 assert_equal([1, 2, 3], extend([1, 2], [3]))
683 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
684 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
685 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100686
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100687 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
688 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
689 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
690 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100691
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100692 var res: list<dict<any>>
693 extend(res, mapnew([1, 2], (_, v) => ({})))
694 assert_equal([{}, {}], res)
695 END
696 CheckDefAndScriptSuccess(lines)
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100697
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200698 CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100699 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
700 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
701 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
702
Bram Moolenaare0de1712020-12-02 17:36:54 +0100703 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
704 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
705 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
Bram Moolenaar351ead02021-01-16 16:07:01 +0100706
707 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
Bram Moolenaare32e5162021-01-21 20:21:29 +0100708 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100709enddef
710
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100711func g:ExtendDict(d)
712 call extend(a:d, #{xx: 'x'})
713endfunc
714
715def Test_extend_dict_item_type()
716 var lines =<< trim END
717 var d: dict<number> = {a: 1}
718 extend(d, {b: 2})
719 END
720 CheckDefAndScriptSuccess(lines)
721
722 lines =<< trim END
723 var d: dict<number> = {a: 1}
724 extend(d, {b: 'x'})
725 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100726 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100727
728 lines =<< trim END
729 var d: dict<number> = {a: 1}
730 g:ExtendDict(d)
731 END
732 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
733 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
734enddef
735
736func g:ExtendList(l)
737 call extend(a:l, ['x'])
738endfunc
739
740def Test_extend_list_item_type()
741 var lines =<< trim END
742 var l: list<number> = [1]
743 extend(l, [2])
744 END
745 CheckDefAndScriptSuccess(lines)
746
747 lines =<< trim END
748 var l: list<number> = [1]
749 extend(l, ['x'])
750 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100751 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100752
753 lines =<< trim END
754 var l: list<number> = [1]
755 g:ExtendList(l)
756 END
757 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
758 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
759enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200760
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200761def Test_extend_return_type()
762 var l = extend([1, 2], [3])
763 var res = 0
764 for n in l
765 res += n
766 endfor
767 res->assert_equal(6)
768enddef
769
Bram Moolenaar93e1cae2021-03-13 21:24:56 +0100770def Test_extend_with_error_function()
771 var lines =<< trim END
772 vim9script
773 def F()
774 {
775 var m = 10
776 }
777 echo m
778 enddef
779
780 def Test()
781 var d: dict<any> = {}
782 d->extend({A: 10, Func: function('F', [])})
783 enddef
784
785 Test()
786 END
787 CheckScriptFailure(lines, 'E1001: Variable not found: m')
788enddef
789
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200790def Test_extendnew()
791 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
792 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
793
794 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
795 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
796 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
797 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
798enddef
799
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200800def Test_feedkeys()
801 CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
802 CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
803 CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
804 g:TestVar = 1
805 feedkeys(":g:TestVar = 789\n", 'xt')
806 assert_equal(789, g:TestVar)
807 unlet g:TestVar
808enddef
809
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100810def Test_filereadable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100811 assert_false(filereadable(""))
812 assert_false(filereadable(test_null_string()))
813
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200814 CheckDefExecFailure(['echo filereadable(123)'], 'E1013:')
815 CheckDefExecFailure(['echo filereadable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100816enddef
817
818def Test_filewritable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100819 assert_false(filewritable(""))
820 assert_false(filewritable(test_null_string()))
821
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200822 CheckDefExecFailure(['echo filewritable(123)'], 'E1013:')
823 CheckDefExecFailure(['echo filewritable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100824enddef
825
826def Test_finddir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200827 CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
828 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 +0100829 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200830 CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
831 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 +0100832enddef
833
834def Test_findfile()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200835 CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
836 CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
837 CheckDefExecFailure(['findfile("")'], 'E1175:')
838 CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
839 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 +0100840enddef
841
Bram Moolenaar3b690062021-02-01 20:14:51 +0100842def Test_flattennew()
843 var lines =<< trim END
844 var l = [1, [2, [3, 4]], 5]
845 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
846 call assert_equal([1, [2, [3, 4]], 5], l)
847
848 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
849 call assert_equal([1, [2, [3, 4]], 5], l)
850 END
851 CheckDefAndScriptSuccess(lines)
852
853 lines =<< trim END
854 echo flatten([1, 2, 3])
855 END
856 CheckDefAndScriptFailure(lines, 'E1158:')
857enddef
858
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200859" Test for float functions argument type
860def Test_float_funcs_args()
861 CheckFeature float
862
863 # acos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200864 CheckDefFailure(['acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200865 # asin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200866 CheckDefFailure(['asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200867 # atan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200868 CheckDefFailure(['atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200869 # atan2()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200870 CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
871 CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
872 CheckDefFailure(['atan2(1.2)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200873 # ceil()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200874 CheckDefFailure(['ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200875 # cos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200876 CheckDefFailure(['cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200877 # cosh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200878 CheckDefFailure(['cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200879 # exp()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200880 CheckDefFailure(['exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200881 # float2nr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200882 CheckDefFailure(['float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200883 # floor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200884 CheckDefFailure(['floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200885 # fmod()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200886 CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
887 CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
888 CheckDefFailure(['fmod(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200889 # isinf()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200890 CheckDefFailure(['isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200891 # isnan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200892 CheckDefFailure(['isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200893 # log()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200894 CheckDefFailure(['log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200895 # log10()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200896 CheckDefFailure(['log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200897 # pow()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200898 CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
899 CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
900 CheckDefFailure(['pow(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200901 # round()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200902 CheckDefFailure(['round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200903 # sin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200904 CheckDefFailure(['sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200905 # sinh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200906 CheckDefFailure(['sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200907 # sqrt()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200908 CheckDefFailure(['sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200909 # tan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200910 CheckDefFailure(['tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200911 # tanh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200912 CheckDefFailure(['tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200913 # trunc()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200914 CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200915enddef
916
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200917def Test_fnameescape()
918 CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
919 assert_equal('\+a\%b\|', fnameescape('+a%b|'))
920enddef
921
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100922def Test_fnamemodify()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100923 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
924 CheckDefSuccess(['echo fnamemodify("", ":p")'])
925 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
926 CheckDefSuccess(['echo fnamemodify("file", "")'])
927
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200928 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool')
929 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special')
930 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100931enddef
932
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100933def Wrong_dict_key_type(items: list<number>): list<number>
934 return filter(items, (_, val) => get({[val]: 1}, 'x'))
935enddef
936
Bram Moolenaar94738d82020-10-21 14:25:07 +0200937def Test_filter_wrong_dict_key_type()
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100938 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200939enddef
940
941def Test_filter_return_type()
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200942 var l = filter([1, 2, 3], (_, _) => 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200943 var res = 0
944 for n in l
945 res += n
946 endfor
947 res->assert_equal(6)
948enddef
949
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100950def Test_filter_missing_argument()
951 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200952 var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100953 res->assert_equal({aa: [1], ac: [3]})
954enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200955
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200956def Test_foldclosed()
957 CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any')
958 assert_equal(-1, foldclosed(1))
959 assert_equal(-1, foldclosed('$'))
960enddef
961
962def Test_foldclosedend()
963 CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
964 assert_equal(-1, foldclosedend(1))
965 assert_equal(-1, foldclosedend('w0'))
966enddef
967
968def Test_foldlevel()
969 CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
970 assert_equal(0, foldlevel(1))
971 assert_equal(0, foldlevel('.'))
972enddef
973
974def Test_foldtextresult()
975 CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
976 assert_equal('', foldtextresult(1))
977 assert_equal('', foldtextresult('.'))
978enddef
979
Bram Moolenaar7d840e92021-05-26 21:10:11 +0200980def Test_fullcommand()
981 assert_equal('next', fullcommand('n'))
982 assert_equal('noremap', fullcommand('no'))
983 assert_equal('noremap', fullcommand('nor'))
984 assert_equal('normal', fullcommand('norm'))
985
986 assert_equal('', fullcommand('k'))
987 assert_equal('keepmarks', fullcommand('ke'))
988 assert_equal('keepmarks', fullcommand('kee'))
989 assert_equal('keepmarks', fullcommand('keep'))
990 assert_equal('keepjumps', fullcommand('keepj'))
991
992 assert_equal('dlist', fullcommand('dl'))
993 assert_equal('', fullcommand('dp'))
994 assert_equal('delete', fullcommand('del'))
995 assert_equal('', fullcommand('dell'))
996 assert_equal('', fullcommand('delp'))
997
998 assert_equal('srewind', fullcommand('sre'))
999 assert_equal('scriptnames', fullcommand('scr'))
1000 assert_equal('', fullcommand('scg'))
1001enddef
1002
Bram Moolenaar94738d82020-10-21 14:25:07 +02001003def Test_garbagecollect()
1004 garbagecollect(true)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001005 CheckDefAndScriptFailure2(['garbagecollect("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
1006 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 +02001007enddef
1008
1009def Test_getbufinfo()
1010 var bufinfo = getbufinfo(bufnr())
1011 getbufinfo('%')->assert_equal(bufinfo)
1012
1013 edit Xtestfile1
1014 hide edit Xtestfile2
1015 hide enew
Bram Moolenaare0de1712020-12-02 17:36:54 +01001016 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001017 ->len()->assert_equal(3)
1018 bwipe Xtestfile1 Xtestfile2
1019enddef
1020
1021def Test_getbufline()
1022 e SomeFile
1023 var buf = bufnr()
1024 e #
1025 var lines = ['aaa', 'bbb', 'ccc']
1026 setbufline(buf, 1, lines)
1027 getbufline('#', 1, '$')->assert_equal(lines)
Bram Moolenaare6e70a12020-10-22 18:23:38 +02001028 getbufline(-1, '$', '$')->assert_equal([])
1029 getbufline(-1, 1, '$')->assert_equal([])
Bram Moolenaar94738d82020-10-21 14:25:07 +02001030
1031 bwipe!
1032enddef
1033
1034def Test_getchangelist()
1035 new
1036 setline(1, 'some text')
1037 var changelist = bufnr()->getchangelist()
1038 getchangelist('%')->assert_equal(changelist)
1039 bwipe!
1040enddef
1041
1042def Test_getchar()
1043 while getchar(0)
1044 endwhile
1045 getchar(true)->assert_equal(0)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001046 getchar(1)->assert_equal(0)
1047 CheckDefAndScriptFailure2(['getchar(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1048 CheckDefAndScriptFailure2(['getchar("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
1049enddef
1050
1051def Test_getcharpos()
1052 CheckDefAndScriptFailure2(['getcharpos(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1053 CheckDefAndScriptFailure2(['getcharpos(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1054enddef
1055
1056def Test_getcharstr()
1057 CheckDefAndScriptFailure2(['getcharstr(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1058 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 +02001059enddef
1060
Bram Moolenaar7ad67d12021-03-10 16:08:26 +01001061def Test_getenv()
1062 if getenv('does-not_exist') == ''
1063 assert_report('getenv() should return null')
1064 endif
1065 if getenv('does-not_exist') == null
1066 else
1067 assert_report('getenv() should return null')
1068 endif
1069 $SOMEENVVAR = 'some'
1070 assert_equal('some', getenv('SOMEENVVAR'))
1071 unlet $SOMEENVVAR
1072enddef
1073
Bram Moolenaar94738d82020-10-21 14:25:07 +02001074def Test_getcompletion()
1075 set wildignore=*.vim,*~
1076 var l = getcompletion('run', 'file', true)
1077 l->assert_equal([])
1078 set wildignore&
1079enddef
1080
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001081def Test_getcurpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001082 CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001083enddef
1084
1085def Test_getcursorcharpos()
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_getcwd()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001090 CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1091 CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1092 CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001093enddef
1094
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001095def Test_getfontname()
1096 CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1097enddef
1098
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001099def Test_getfperm()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001100 assert_equal('', getfperm(""))
1101 assert_equal('', getfperm(test_null_string()))
1102
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001103 CheckDefExecFailure(['echo getfperm(true)'], 'E1013:')
1104 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001105enddef
1106
1107def Test_getfsize()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001108 assert_equal(-1, getfsize(""))
1109 assert_equal(-1, getfsize(test_null_string()))
1110
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001111 CheckDefExecFailure(['echo getfsize(true)'], 'E1013:')
1112 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001113enddef
1114
1115def Test_getftime()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001116 assert_equal(-1, getftime(""))
1117 assert_equal(-1, getftime(test_null_string()))
1118
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001119 CheckDefExecFailure(['echo getftime(true)'], 'E1013:')
1120 CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001121enddef
1122
1123def Test_getftype()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001124 assert_equal('', getftype(""))
1125 assert_equal('', getftype(test_null_string()))
1126
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001127 CheckDefExecFailure(['echo getftype(true)'], 'E1013:')
1128 CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001129enddef
1130
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001131def Test_getjumplist()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001132 CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1133 CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1134 CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001135enddef
1136
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001137def Test_getline()
1138 var lines =<< trim END
1139 new
1140 setline(1, ['hello', 'there', 'again'])
1141 assert_equal('hello', getline(1))
1142 assert_equal('hello', getline('.'))
1143
1144 normal 2Gvjv
1145 assert_equal('there', getline("'<"))
1146 assert_equal('again', getline("'>"))
1147 END
1148 CheckDefAndScriptSuccess(lines)
1149
1150 lines =<< trim END
1151 echo getline('1')
1152 END
1153 CheckDefExecAndScriptFailure(lines, 'E1209:')
1154enddef
1155
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001156def Test_getloclist()
1157 CheckDefAndScriptFailure2(['getloclist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1158 CheckDefAndScriptFailure2(['getloclist(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
1159enddef
1160
1161def Test_getloclist_return_type()
1162 var l = getloclist(1)
1163 l->assert_equal([])
1164
1165 var d = getloclist(1, {items: 0})
1166 d->assert_equal({items: []})
1167enddef
1168
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001169def Test_getmarklist()
1170 CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1171 assert_equal([], getmarklist(10000))
1172 assert_fails('getmarklist("a%b@#")', 'E94:')
1173enddef
1174
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001175def Test_getmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001176 CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001177enddef
1178
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001179def Test_getpos()
1180 CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1181 assert_equal([0, 1, 1, 0], getpos('.'))
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001182 CheckDefExecFailure(['getpos("a")'], 'E1209:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001183enddef
1184
1185def Test_getqflist()
1186 CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1187 call assert_equal({}, getqflist({}))
1188enddef
1189
Bram Moolenaar94738d82020-10-21 14:25:07 +02001190def Test_getqflist_return_type()
1191 var l = getqflist()
1192 l->assert_equal([])
1193
Bram Moolenaare0de1712020-12-02 17:36:54 +01001194 var d = getqflist({items: 0})
1195 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001196enddef
1197
1198def Test_getreg()
1199 var lines = ['aaa', 'bbb', 'ccc']
1200 setreg('a', lines)
1201 getreg('a', true, true)->assert_equal(lines)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001202 assert_fails('getreg("ab")', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001203enddef
1204
1205def Test_getreg_return_type()
1206 var s1: string = getreg('"')
1207 var s2: string = getreg('"', 1)
1208 var s3: list<string> = getreg('"', 1, 1)
1209enddef
1210
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001211def Test_getreginfo()
1212 var text = 'abc'
1213 setreg('a', text)
1214 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
1215 assert_fails('getreginfo("ab")', 'E1162:')
1216enddef
1217
1218def Test_getregtype()
1219 var lines = ['aaa', 'bbb', 'ccc']
1220 setreg('a', lines)
1221 getregtype('a')->assert_equal('V')
1222 assert_fails('getregtype("ab")', 'E1162:')
1223enddef
1224
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001225def Test_gettabinfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001226 CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001227enddef
1228
1229def Test_gettagstack()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001230 CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001231enddef
1232
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001233def Test_gettext()
1234 CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1235 assert_equal('abc', gettext("abc"))
1236enddef
1237
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001238def Test_getwininfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001239 CheckDefFailure(['getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001240enddef
1241
1242def Test_getwinpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001243 CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001244enddef
1245
Bram Moolenaar94738d82020-10-21 14:25:07 +02001246def Test_glob()
1247 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
1248enddef
1249
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001250def Test_glob2regpat()
1251 CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1252 assert_equal('^$', glob2regpat(''))
1253enddef
1254
Bram Moolenaar94738d82020-10-21 14:25:07 +02001255def Test_globpath()
1256 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
1257enddef
1258
1259def Test_has()
1260 has('eval', true)->assert_equal(1)
1261enddef
1262
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001263def Test_has_key()
Bram Moolenaar1aeddeb2021-07-11 14:55:49 +02001264 var d = {123: 'xx'}
1265 assert_true(has_key(d, '123'))
1266 assert_true(has_key(d, 123))
1267 assert_false(has_key(d, 'x'))
1268 assert_false(has_key(d, 99))
1269
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001270 CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1271 CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1272enddef
1273
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001274def Test_haslocaldir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001275 CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1276 CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1277 CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001278enddef
1279
Bram Moolenaar94738d82020-10-21 14:25:07 +02001280def Test_hasmapto()
1281 hasmapto('foobar', 'i', true)->assert_equal(0)
1282 iabbrev foo foobar
1283 hasmapto('foobar', 'i', true)->assert_equal(1)
1284 iunabbrev foo
1285enddef
1286
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001287def Test_histadd()
1288 CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1289 CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1290 histadd("search", 'skyblue')
1291 assert_equal('skyblue', histget('/', -1))
1292enddef
1293
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001294def Test_histget()
1295 CheckDefAndScriptFailure2(['histget(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1296 CheckDefAndScriptFailure2(['histget("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1297enddef
1298
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001299def Test_histnr()
1300 CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1301 assert_equal(-1, histnr('abc'))
1302enddef
1303
1304def Test_hlID()
1305 CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1306 assert_equal(0, hlID('NonExistingHighlight'))
1307enddef
1308
1309def Test_hlexists()
1310 CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1311 assert_equal(0, hlexists('NonExistingHighlight'))
1312enddef
1313
1314def Test_iconv()
1315 CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1316 CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1317 CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1318 assert_equal('abc', iconv('abc', 'fromenc', 'toenc'))
1319enddef
1320
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001321def Test_indent()
1322 CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number')
1323 CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
1324 assert_equal(0, indent(1))
1325enddef
1326
Bram Moolenaar94738d82020-10-21 14:25:07 +02001327def Test_index()
1328 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
1329enddef
1330
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001331def Test_input()
1332 CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1333 CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1334 CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1335 CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value')
1336enddef
1337
1338def Test_inputdialog()
1339 CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1340 CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1341 CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1342 CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1343enddef
1344
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001345def Test_inputlist()
1346 CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number')
1347 CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
1348 CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
1349 feedkeys("2\<CR>", 't')
1350 var r: number = inputlist(['a', 'b', 'c'])
1351 assert_equal(2, r)
1352enddef
1353
1354def Test_inputsecret()
1355 CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1356 CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1357 feedkeys("\<CR>", 't')
1358 var ans: string = inputsecret('Pass:', '123')
1359 assert_equal('123', ans)
1360enddef
1361
Bram Moolenaar193f6202020-11-16 20:08:35 +01001362let s:number_one = 1
1363let s:number_two = 2
1364let s:string_keep = 'keep'
1365
Bram Moolenaarca174532020-10-21 16:42:22 +02001366def Test_insert()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001367 var l = insert([2, 1], 3)
1368 var res = 0
1369 for n in l
1370 res += n
1371 endfor
1372 res->assert_equal(6)
Bram Moolenaarca174532020-10-21 16:42:22 +02001373
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001374 var m: any = []
1375 insert(m, 4)
1376 call assert_equal([4], m)
1377 extend(m, [6], 0)
1378 call assert_equal([6, 4], m)
1379
Bram Moolenaar39211cb2021-04-18 15:48:04 +02001380 var lines =<< trim END
1381 insert(test_null_list(), 123)
1382 END
1383 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
1384
1385 lines =<< trim END
1386 insert(test_null_blob(), 123)
1387 END
1388 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
1389
Bram Moolenaarca174532020-10-21 16:42:22 +02001390 assert_equal([1, 2, 3], insert([2, 3], 1))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001391 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
Bram Moolenaarca174532020-10-21 16:42:22 +02001392 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001393 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
Bram Moolenaarca174532020-10-21 16:42:22 +02001394 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
1395 assert_equal(0z1234, insert(0z34, 0x12))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001396
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001397 CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
Bram Moolenaarca174532020-10-21 16:42:22 +02001398 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
1399 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001400enddef
1401
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001402def Test_invert()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001403 CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001404enddef
1405
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001406def Test_isdirectory()
1407 CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
1408 assert_false(isdirectory('NonExistingDir'))
1409enddef
1410
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001411def Test_islocked()
1412 CheckDefAndScriptFailure2(['islocked(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1413 CheckDefAndScriptFailure2(['var n1: number = 10', 'islocked(n1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1414 g:v1 = 10
1415 assert_false(islocked('g:v1'))
1416 lockvar g:v1
1417 assert_true(islocked('g:v1'))
1418 unlet g:v1
1419enddef
1420
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001421def Test_items()
1422 CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1423 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items())
1424 assert_equal([], {}->items())
1425enddef
1426
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001427def Test_job_getchannel()
1428 CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1429 assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job')
1430enddef
1431
1432def Test_job_info()
1433 CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1434 assert_fails('job_info(test_null_job())', 'E916: not a valid job')
1435enddef
1436
1437def Test_job_info_return_type()
1438 if has('job')
1439 job_start(&shell)
1440 var jobs = job_info()
1441 assert_equal('list<job>', typename(jobs))
1442 assert_equal('dict<any>', typename(job_info(jobs[0])))
1443 job_stop(jobs[0])
1444 endif
1445enddef
1446
1447def Test_job_status()
1448 CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1449 assert_equal('fail', job_status(test_null_job()))
1450enddef
1451
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001452def Test_js_decode()
1453 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1454 assert_equal([1, 2], js_decode('[1,2]'))
1455enddef
1456
1457def Test_json_decode()
1458 CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1459 assert_equal(1.0, json_decode('1.0'))
1460enddef
1461
1462def Test_keys()
1463 CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1464 assert_equal(['a'], {a: 'v'}->keys())
1465 assert_equal([], {}->keys())
1466enddef
1467
Bram Moolenaar94738d82020-10-21 14:25:07 +02001468def Test_keys_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001469 const var: list<string> = {a: 1, b: 2}->keys()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001470 var->assert_equal(['a', 'b'])
1471enddef
1472
Bram Moolenaarc5809432021-03-27 21:23:30 +01001473def Test_line()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001474 assert_fails('line(true)', 'E1174:')
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001475 CheckDefAndScriptFailure2(['line(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1476 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 +02001477enddef
1478
1479def Test_line2byte()
1480 CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1481 assert_equal(-1, line2byte(1))
1482 assert_equal(-1, line2byte(10000))
1483enddef
1484
1485def Test_lispindent()
1486 CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1487 assert_equal(0, lispindent(1))
Bram Moolenaarc5809432021-03-27 21:23:30 +01001488enddef
1489
Bram Moolenaar94738d82020-10-21 14:25:07 +02001490def Test_list2str_str2list_utf8()
1491 var s = "\u3042\u3044"
1492 var l = [0x3042, 0x3044]
1493 str2list(s, true)->assert_equal(l)
1494 list2str(l, true)->assert_equal(s)
1495enddef
1496
1497def SID(): number
1498 return expand('<SID>')
1499 ->matchstr('<SNR>\zs\d\+\ze_$')
1500 ->str2nr()
1501enddef
1502
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001503def Test_listener_flush()
1504 CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1505enddef
1506
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001507def Test_listener_remove()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001508 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 +02001509enddef
1510
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001511def Test_map_function_arg()
1512 var lines =<< trim END
1513 def MapOne(i: number, v: string): string
1514 return i .. ':' .. v
1515 enddef
1516 var l = ['a', 'b', 'c']
1517 map(l, MapOne)
1518 assert_equal(['0:a', '1:b', '2:c'], l)
1519 END
1520 CheckDefAndScriptSuccess(lines)
Bram Moolenaar8da6d6d2021-06-05 18:15:09 +02001521
1522 lines =<< trim END
1523 range(3)->map((a, b, c) => a + b + c)
1524 END
1525 CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
1526 lines =<< trim END
1527 range(3)->map((a, b, c, d) => a + b + c + d)
1528 END
1529 CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001530enddef
1531
1532def Test_map_item_type()
1533 var lines =<< trim END
1534 var l = ['a', 'b', 'c']
1535 map(l, (k, v) => k .. '/' .. v )
1536 assert_equal(['0/a', '1/b', '2/c'], l)
1537 END
1538 CheckDefAndScriptSuccess(lines)
1539
1540 lines =<< trim END
1541 var l: list<number> = [0]
1542 echo map(l, (_, v) => [])
1543 END
1544 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1545
1546 lines =<< trim END
1547 var l: list<number> = range(2)
1548 echo map(l, (_, v) => [])
1549 END
1550 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1551
1552 lines =<< trim END
1553 var d: dict<number> = {key: 0}
1554 echo map(d, (_, v) => [])
1555 END
1556 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1557enddef
1558
Bram Moolenaar94738d82020-10-21 14:25:07 +02001559def Test_maparg()
1560 var lnum = str2nr(expand('<sflnum>'))
1561 map foo bar
Bram Moolenaare0de1712020-12-02 17:36:54 +01001562 maparg('foo', '', false, true)->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001563 lnum: lnum + 1,
1564 script: 0,
1565 mode: ' ',
1566 silent: 0,
1567 noremap: 0,
1568 lhs: 'foo',
1569 lhsraw: 'foo',
1570 nowait: 0,
1571 expr: 0,
1572 sid: SID(),
1573 rhs: 'bar',
1574 buffer: 0})
1575 unmap foo
1576enddef
1577
1578def Test_mapcheck()
1579 iabbrev foo foobar
1580 mapcheck('foo', 'i', true)->assert_equal('foobar')
1581 iunabbrev foo
1582enddef
1583
1584def Test_maparg_mapset()
1585 nnoremap <F3> :echo "hit F3"<CR>
1586 var mapsave = maparg('<F3>', 'n', false, true)
1587 mapset('n', false, mapsave)
1588
1589 nunmap <F3>
1590enddef
1591
Bram Moolenaar027c4ab2021-02-21 16:20:18 +01001592def Test_map_failure()
1593 CheckFeature job
1594
1595 var lines =<< trim END
1596 vim9script
1597 writefile([], 'Xtmpfile')
1598 silent e Xtmpfile
1599 var d = {[bufnr('%')]: {a: 0}}
1600 au BufReadPost * Func()
1601 def Func()
1602 if d->has_key('')
1603 endif
1604 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
1605 enddef
1606 e
1607 END
1608 CheckScriptFailure(lines, 'E1013:')
1609 au! BufReadPost
1610 delete('Xtmpfile')
1611enddef
1612
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001613def Test_match()
1614 CheckDefAndScriptFailure2(['match(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1615 CheckDefAndScriptFailure2(['match(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1616 CheckDefAndScriptFailure2(['match("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1617 CheckDefAndScriptFailure2(['match("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1618 assert_equal(2, match('ab12cd', '12'))
1619 assert_equal(-1, match('ab12cd', '34'))
1620 assert_equal(6, match('ab12cd12ef', '12', 4))
1621 assert_equal(2, match('abcd', '..', 0, 3))
1622 assert_equal(1, match(['a', 'b', 'c'], 'b'))
1623 assert_equal(-1, match(['a', 'b', 'c'], 'd'))
1624 assert_equal(3, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1625 assert_equal(5, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1626enddef
1627
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001628def Test_matcharg()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001629 CheckDefFailure(['matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001630enddef
1631
1632def Test_matchdelete()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001633 CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1634 CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1635 CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001636enddef
1637
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001638def Test_matchend()
1639 CheckDefAndScriptFailure2(['matchend(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1640 CheckDefAndScriptFailure2(['matchend(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1641 CheckDefAndScriptFailure2(['matchend("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1642 CheckDefAndScriptFailure2(['matchend("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1643 assert_equal(4, matchend('ab12cd', '12'))
1644 assert_equal(-1, matchend('ab12cd', '34'))
1645 assert_equal(8, matchend('ab12cd12ef', '12', 4))
1646 assert_equal(4, matchend('abcd', '..', 0, 3))
1647 assert_equal(1, matchend(['a', 'b', 'c'], 'b'))
1648 assert_equal(-1, matchend(['a', 'b', 'c'], 'd'))
1649 assert_equal(3, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1650 assert_equal(5, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1651enddef
1652
1653def Test_matchlist()
1654 CheckDefAndScriptFailure2(['matchlist(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1655 CheckDefAndScriptFailure2(['matchlist(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1656 CheckDefAndScriptFailure2(['matchlist("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1657 CheckDefAndScriptFailure2(['matchlist("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1658 var l: list<string> = ['12', '', '', '', '', '', '', '', '', '']
1659 assert_equal(l, matchlist('ab12cd', '12'))
1660 assert_equal([], matchlist('ab12cd', '34'))
1661 assert_equal(l, matchlist('ab12cd12ef', '12', 4))
1662 l[0] = 'cd'
1663 assert_equal(l, matchlist('abcd', '..', 0, 3))
1664 l[0] = 'b'
1665 assert_equal(l, matchlist(['a', 'b', 'c'], 'b'))
1666 assert_equal([], matchlist(['a', 'b', 'c'], 'd'))
1667 assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1668 assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1669enddef
1670
1671def Test_matchstr()
1672 CheckDefAndScriptFailure2(['matchstr(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1673 CheckDefAndScriptFailure2(['matchstr(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1674 CheckDefAndScriptFailure2(['matchstr("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1675 CheckDefAndScriptFailure2(['matchstr("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1676 assert_equal('12', matchstr('ab12cd', '12'))
1677 assert_equal('', matchstr('ab12cd', '34'))
1678 assert_equal('12', matchstr('ab12cd12ef', '12', 4))
1679 assert_equal('cd', matchstr('abcd', '..', 0, 3))
1680 assert_equal('b', matchstr(['a', 'b', 'c'], 'b'))
1681 assert_equal('', matchstr(['a', 'b', 'c'], 'd'))
1682 assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1683 assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1684enddef
1685
1686def Test_matchstrpos()
1687 CheckDefAndScriptFailure2(['matchstrpos(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1688 CheckDefAndScriptFailure2(['matchstrpos(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1689 CheckDefAndScriptFailure2(['matchstrpos("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1690 CheckDefAndScriptFailure2(['matchstrpos("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1691 assert_equal(['12', 2, 4], matchstrpos('ab12cd', '12'))
1692 assert_equal(['', -1, -1], matchstrpos('ab12cd', '34'))
1693 assert_equal(['12', 6, 8], matchstrpos('ab12cd12ef', '12', 4))
1694 assert_equal(['cd', 2, 4], matchstrpos('abcd', '..', 0, 3))
1695 assert_equal(['b', 1, 0, 1], matchstrpos(['a', 'b', 'c'], 'b'))
1696 assert_equal(['', -1, -1, -1], matchstrpos(['a', 'b', 'c'], 'd'))
1697 assert_equal(['b', 3, 0, 1],
1698 matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1699 assert_equal(['b', 5, 0, 1],
1700 matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1701enddef
1702
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001703def Test_max()
1704 g:flag = true
1705 var l1: list<number> = g:flag
1706 ? [1, max([2, 3])]
1707 : [4, 5]
1708 assert_equal([1, 3], l1)
1709
1710 g:flag = false
1711 var l2: list<number> = g:flag
1712 ? [1, max([2, 3])]
1713 : [4, 5]
1714 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001715 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 +01001716enddef
1717
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001718def Test_menu_info()
1719 CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1720 CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1721 CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1722 assert_equal({}, menu_info('aMenu'))
1723enddef
1724
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001725def Test_min()
1726 g:flag = true
1727 var l1: list<number> = g:flag
1728 ? [1, min([2, 3])]
1729 : [4, 5]
1730 assert_equal([1, 2], l1)
1731
1732 g:flag = false
1733 var l2: list<number> = g:flag
1734 ? [1, min([2, 3])]
1735 : [4, 5]
1736 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001737 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 +01001738enddef
1739
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001740def Test_mkdir()
1741 CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1742 CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
1743 CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1744 delete('a', 'rf')
1745enddef
1746
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001747def Test_mode()
1748 CheckDefFailure(['mode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
1749 CheckDefFailure(['mode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
1750enddef
1751
1752def Test_mzeval()
1753 if !has('mzscheme')
1754 CheckFeature mzscheme
1755 endif
Bram Moolenaar20c370d2021-07-16 10:39:28 +02001756 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 +02001757enddef
1758
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001759def Test_nextnonblank()
1760 CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1761 assert_equal(0, nextnonblank(1))
1762enddef
1763
Bram Moolenaar94738d82020-10-21 14:25:07 +02001764def Test_nr2char()
1765 nr2char(97, true)->assert_equal('a')
1766enddef
1767
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001768def Test_or()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001769 CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1770 CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1771enddef
1772
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001773def Test_pathshorten()
1774 CheckDefAndScriptFailure2(['pathshorten(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1775 CheckDefAndScriptFailure2(['pathshorten("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1776enddef
1777
1778def Test_perleval()
1779 if !has('perl')
1780 CheckFeature perl
1781 endif
1782 CheckDefAndScriptFailure2(['perleval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1783enddef
1784
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001785def Test_popup_atcursor()
1786 CheckDefAndScriptFailure2(['popup_atcursor({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1787 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 +02001788
1789 # Pass variable of type 'any' to popup_atcursor()
1790 var what: any = 'Hello'
1791 var popupID = what->popup_atcursor({moved: 'any'})
1792 assert_equal(0, popupID->popup_getoptions().tabpage)
1793 popupID->popup_close()
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001794enddef
1795
1796def Test_popup_beval()
1797 CheckDefAndScriptFailure2(['popup_beval({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1798 CheckDefAndScriptFailure2(['popup_beval("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1799enddef
1800
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001801def Test_popup_clear()
1802 CheckDefAndScriptFailure2(['popup_clear(["a"])'], 'E1013: Argument 1: type mismatch, expected bool but got list<string>', 'E745: Using a List as a Number')
1803 CheckDefAndScriptFailure2(['popup_clear(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1804enddef
1805
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02001806def Test_popup_create()
1807 # Pass variable of type 'any' to popup_create()
1808 var what: any = 'Hello'
1809 var popupID = what->popup_create({})
1810 assert_equal(0, popupID->popup_getoptions().tabpage)
1811 popupID->popup_close()
1812enddef
1813
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001814def Test_popup_dialog()
1815 CheckDefAndScriptFailure2(['popup_dialog({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1816 CheckDefAndScriptFailure2(['popup_dialog("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_filter_menu()
1820 CheckDefAndScriptFailure2(['popup_filter_menu("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1821 CheckDefAndScriptFailure2(['popup_filter_menu(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1822enddef
1823
1824def Test_popup_filter_yesno()
1825 CheckDefAndScriptFailure2(['popup_filter_yesno("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1826 CheckDefAndScriptFailure2(['popup_filter_yesno(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1827enddef
1828
1829def Test_popup_getoptions()
1830 CheckDefAndScriptFailure2(['popup_getoptions("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1831 CheckDefAndScriptFailure2(['popup_getoptions(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1832enddef
1833
1834def Test_popup_getpos()
1835 CheckDefAndScriptFailure2(['popup_getpos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1836 CheckDefAndScriptFailure2(['popup_getpos(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1837enddef
1838
1839def Test_popup_hide()
1840 CheckDefAndScriptFailure2(['popup_hide("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1841 CheckDefAndScriptFailure2(['popup_hide(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1842enddef
1843
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001844def Test_popup_locate()
1845 CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1846 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 +02001847enddef
1848
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001849def Test_popup_menu()
1850 CheckDefAndScriptFailure2(['popup_menu({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1851 CheckDefAndScriptFailure2(['popup_menu("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1852enddef
1853
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001854def Test_popup_move()
1855 CheckDefAndScriptFailure2(['popup_move("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1856 CheckDefAndScriptFailure2(['popup_move(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1857enddef
1858
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001859def Test_popup_notification()
1860 CheckDefAndScriptFailure2(['popup_notification({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1861 CheckDefAndScriptFailure2(['popup_notification("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1862enddef
1863
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001864def Test_popup_setoptions()
1865 CheckDefAndScriptFailure2(['popup_setoptions("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1866 CheckDefAndScriptFailure2(['popup_setoptions(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1867enddef
1868
1869def Test_popup_show()
1870 CheckDefAndScriptFailure2(['popup_show("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1871 CheckDefAndScriptFailure2(['popup_show(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1872enddef
1873
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001874def Test_prevnonblank()
1875 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1876 assert_equal(0, prevnonblank(1))
1877enddef
1878
1879def Test_prompt_getprompt()
Dominique Pelle74509232021-07-03 19:27:37 +02001880 if has('channel')
1881 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1882 assert_equal('', prompt_getprompt('NonExistingBuf'))
1883 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001884enddef
1885
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001886def Test_prompt_setprompt()
1887 if !has('channel')
1888 CheckFeature channel
1889 endif
1890 CheckDefAndScriptFailure2(['prompt_setprompt([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
1891 CheckDefAndScriptFailure2(['prompt_setprompt(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
1892enddef
1893
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001894def Test_prop_find()
1895 CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1896 CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1897 CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1898enddef
1899
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001900def Test_prop_list()
1901 CheckDefAndScriptFailure2(['prop_list("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1902 CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1903enddef
1904
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001905def Test_prop_type_add()
1906 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')
1907 CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1908enddef
1909
1910def Test_prop_type_change()
1911 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')
1912 CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1913enddef
1914
1915def Test_prop_type_delete()
1916 CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1917 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')
1918 CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1919enddef
1920
1921def Test_prop_type_get()
1922 CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1923 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')
1924 CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1925enddef
1926
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001927def Test_prop_type_list()
1928 CheckDefAndScriptFailure2(['prop_type_list(["a"])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
1929 CheckDefAndScriptFailure2(['prop_type_list(2)'], 'E1013: Argument 1: type mismatch, expected dict<any> but got number', 'E715: Dictionary required')
1930enddef
1931
1932def Test_py3eval()
1933 if !has('python3')
1934 CheckFeature python3
1935 endif
1936 CheckDefAndScriptFailure2(['py3eval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1937enddef
1938
1939def Test_pyeval()
1940 if !has('python')
1941 CheckFeature python
1942 endif
1943 CheckDefAndScriptFailure2(['pyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1944enddef
1945
1946def Test_pyxeval()
1947 if !has('python') && !has('python3')
1948 CheckFeature python
1949 endif
1950 CheckDefAndScriptFailure2(['pyxeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1951enddef
1952
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001953def Test_rand()
1954 CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number')
1955 CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1956 assert_true(rand() >= 0)
1957 assert_true(rand(srand()) >= 0)
1958enddef
1959
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001960def Test_range()
1961 CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1962 CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1963 CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1964enddef
1965
Bram Moolenaar94738d82020-10-21 14:25:07 +02001966def Test_readdir()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001967 eval expand('sautest')->readdir((e) => e[0] !=# '.')
1968 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001969enddef
1970
Bram Moolenaarc423ad72021-01-13 20:38:03 +01001971def Test_readblob()
1972 var blob = 0z12341234
1973 writefile(blob, 'Xreadblob')
1974 var read: blob = readblob('Xreadblob')
1975 assert_equal(blob, read)
1976
1977 var lines =<< trim END
1978 var read: list<string> = readblob('Xreadblob')
1979 END
1980 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
1981 delete('Xreadblob')
1982enddef
1983
1984def Test_readfile()
1985 var text = ['aaa', 'bbb', 'ccc']
1986 writefile(text, 'Xreadfile')
1987 var read: list<string> = readfile('Xreadfile')
1988 assert_equal(text, read)
1989
1990 var lines =<< trim END
1991 var read: dict<string> = readfile('Xreadfile')
1992 END
1993 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
1994 delete('Xreadfile')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001995
1996 CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
1997 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 +01001998enddef
1999
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002000def Test_reltime()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002001 CheckFeature reltime
2002
2003 CheckDefExecAndScriptFailure(['[]->reltime()'], 'E474:')
2004 CheckDefExecAndScriptFailure(['[]->reltime([])'], 'E474:')
2005
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002006 CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
2007 CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
2008 CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
2009 CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
2010 var start: list<any> = reltime()
2011 assert_true(type(reltime(start)) == v:t_list)
2012 var end: list<any> = reltime()
2013 assert_true(type(reltime(start, end)) == v:t_list)
2014enddef
2015
2016def Test_reltimefloat()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002017 CheckFeature reltime
2018
2019 CheckDefExecAndScriptFailure(['[]->reltimefloat()'], 'E474:')
2020
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002021 CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
2022 CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
2023 assert_true(type(reltimefloat(reltime())) == v:t_float)
2024enddef
2025
2026def Test_reltimestr()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002027 CheckFeature reltime
2028
2029 CheckDefExecAndScriptFailure(['[]->reltimestr()'], 'E474:')
2030
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002031 CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
2032 CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
2033 assert_true(type(reltimestr(reltime())) == v:t_string)
2034enddef
2035
2036def Test_remote_foreground()
2037 CheckFeature clientserver
2038 # remote_foreground() doesn't fail on MS-Windows
2039 CheckNotMSWindows
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +02002040 CheckEnv DISPLAY
2041
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002042 CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2043 assert_fails('remote_foreground("NonExistingServer")', 'E241:')
2044enddef
2045
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002046def Test_remote_peek()
2047 CheckFeature clientserver
2048 CheckEnv DISPLAY
2049 CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
2050 CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used')
2051enddef
2052
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002053def Test_remote_read()
2054 CheckFeature clientserver
2055 CheckEnv DISPLAY
2056 CheckDefAndScriptFailure2(['remote_read(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2057 CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2058enddef
2059
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002060def Test_remote_startserver()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002061 CheckFeature clientserver
2062 CheckEnv DISPLAY
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002063 CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2064enddef
2065
Bram Moolenaar94738d82020-10-21 14:25:07 +02002066def Test_remove_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002067 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002068 var res = 0
2069 for n in l
2070 res += n
2071 endfor
2072 res->assert_equal(3)
2073enddef
2074
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002075def Test_rename()
2076 CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2077 CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
2078enddef
2079
2080def Test_resolve()
2081 CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2082 assert_equal('SomeFile', resolve('SomeFile'))
2083enddef
2084
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002085def Test_reverse()
2086 CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E899: Argument of reverse() must be a List or Blob')
2087 CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E899: Argument of reverse() must be a List or Blob')
2088enddef
2089
Bram Moolenaar94738d82020-10-21 14:25:07 +02002090def Test_reverse_return_type()
2091 var l = reverse([1, 2, 3])
2092 var res = 0
2093 for n in l
2094 res += n
2095 endfor
2096 res->assert_equal(6)
2097enddef
2098
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002099def Test_rubyeval()
2100 if !has('ruby')
2101 CheckFeature ruby
2102 endif
2103 CheckDefAndScriptFailure2(['rubyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2104enddef
2105
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002106def Test_screenattr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002107 CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2108 CheckDefFailure(['screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002109enddef
2110
2111def Test_screenchar()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002112 CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2113 CheckDefFailure(['screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002114enddef
2115
2116def Test_screenchars()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002117 CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2118 CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002119enddef
2120
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002121def Test_screenpos()
2122 CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2123 CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string')
2124 CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string')
2125 assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1))
2126enddef
2127
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002128def Test_screenstring()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002129 CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2130 CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002131enddef
2132
Bram Moolenaar94738d82020-10-21 14:25:07 +02002133def Test_search()
2134 new
2135 setline(1, ['foo', 'bar'])
2136 var val = 0
2137 # skip expr returns boolean
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002138 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002139 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002140 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002141 # skip expr returns number, only 0 and 1 are accepted
2142 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002143 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002144 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002145 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
2146 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
2147 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002148
2149 setline(1, "find this word")
2150 normal gg
2151 var col = 7
2152 assert_equal(1, search('this', '', 0, 0, 'col(".") > col'))
2153 normal 0
2154 assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col'))
2155
2156 col = 5
2157 normal 0
2158 assert_equal(0, search('this', '', 0, 0, 'col(".") > col'))
2159 normal 0
2160 assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col'))
2161 bwipe!
Bram Moolenaar94738d82020-10-21 14:25:07 +02002162enddef
2163
2164def Test_searchcount()
2165 new
2166 setline(1, "foo bar")
2167 :/foo
Bram Moolenaare0de1712020-12-02 17:36:54 +01002168 searchcount({recompute: true})
2169 ->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02002170 exact_match: 1,
2171 current: 1,
2172 total: 1,
2173 maxcount: 99,
2174 incomplete: 0})
2175 bwipe!
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002176 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 +02002177enddef
2178
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002179def Test_searchpair()
2180 new
2181 setline(1, "here { and } there")
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002182
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002183 normal f{
2184 var col = 15
2185 assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col'))
2186 assert_equal(12, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002187 normal 0f{
2188 assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col'))
2189
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002190 col = 8
2191 normal 0f{
2192 assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col'))
2193 assert_equal(6, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002194 normal 0f{
2195 assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col'))
2196
Bram Moolenaarff652882021-05-16 15:24:49 +02002197 var lines =<< trim END
2198 vim9script
2199 setline(1, '()')
2200 normal gg
2201 def Fail()
2202 try
2203 searchpairpos('(', '', ')', 'nW', '[0]->map("")')
2204 catch
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002205 g:caught = 'yes'
Bram Moolenaarff652882021-05-16 15:24:49 +02002206 endtry
2207 enddef
2208 Fail()
2209 END
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002210 CheckScriptSuccess(lines)
2211 assert_equal('yes', g:caught)
Bram Moolenaarff652882021-05-16 15:24:49 +02002212
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002213 unlet g:caught
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002214 bwipe!
2215enddef
2216
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002217def Test_server2client()
2218 CheckFeature clientserver
2219 CheckEnv DISPLAY
2220 CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2221 CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2222enddef
2223
Bram Moolenaar34453202021-01-31 13:08:38 +01002224def Test_set_get_bufline()
2225 # similar to Test_setbufline_getbufline()
2226 var lines =<< trim END
2227 new
2228 var b = bufnr('%')
2229 hide
2230 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
2231 assert_equal(['foo'], getbufline(b, 1))
2232 assert_equal(['bar'], getbufline(b, '$'))
2233 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
2234 exe "bd!" b
2235 assert_equal([], getbufline(b, 1, 2))
2236
2237 split Xtest
2238 setline(1, ['a', 'b', 'c'])
2239 b = bufnr('%')
2240 wincmd w
2241
2242 assert_equal(1, setbufline(b, 5, 'x'))
2243 assert_equal(1, setbufline(b, 5, ['x']))
2244 assert_equal(1, setbufline(b, 5, []))
2245 assert_equal(1, setbufline(b, 5, test_null_list()))
2246
2247 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
2248 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
2249 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
2250 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
2251
2252 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
2253
2254 assert_equal(0, setbufline(b, 4, ['d', 'e']))
2255 assert_equal(['c'], b->getbufline(3))
2256 assert_equal(['d'], getbufline(b, 4))
2257 assert_equal(['e'], getbufline(b, 5))
2258 assert_equal([], getbufline(b, 6))
2259 assert_equal([], getbufline(b, 2, 1))
2260
Bram Moolenaar00385112021-02-07 14:31:06 +01002261 if has('job')
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002262 setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())])
Bram Moolenaar00385112021-02-07 14:31:06 +01002263 assert_equal(["function('eval')",
2264 "{'key': 123}",
2265 "no process"],
2266 getbufline(b, 2, 4))
2267 endif
Bram Moolenaar34453202021-01-31 13:08:38 +01002268
2269 exe 'bwipe! ' .. b
2270 END
2271 CheckDefAndScriptSuccess(lines)
2272enddef
2273
Bram Moolenaar94738d82020-10-21 14:25:07 +02002274def Test_searchdecl()
2275 searchdecl('blah', true, true)->assert_equal(1)
2276enddef
2277
2278def Test_setbufvar()
2279 setbufvar(bufnr('%'), '&syntax', 'vim')
2280 &syntax->assert_equal('vim')
2281 setbufvar(bufnr('%'), '&ts', 16)
2282 &ts->assert_equal(16)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002283 setbufvar(bufnr('%'), '&ai', true)
2284 &ai->assert_equal(true)
2285 setbufvar(bufnr('%'), '&ft', 'filetype')
2286 &ft->assert_equal('filetype')
2287
Bram Moolenaar94738d82020-10-21 14:25:07 +02002288 settabwinvar(1, 1, '&syntax', 'vam')
2289 &syntax->assert_equal('vam')
2290 settabwinvar(1, 1, '&ts', 15)
2291 &ts->assert_equal(15)
2292 setlocal ts=8
Bram Moolenaarb0d81822021-01-03 15:55:10 +01002293 settabwinvar(1, 1, '&list', false)
2294 &list->assert_equal(false)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002295 settabwinvar(1, 1, '&list', true)
2296 &list->assert_equal(true)
2297 setlocal list&
Bram Moolenaar94738d82020-10-21 14:25:07 +02002298
2299 setbufvar('%', 'myvar', 123)
2300 getbufvar('%', 'myvar')->assert_equal(123)
2301enddef
2302
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002303def Test_setcharsearch()
2304 CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
2305 CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2306 var d: dict<any> = {char: 'x', forward: 1, until: 1}
2307 setcharsearch(d)
2308 assert_equal(d, getcharsearch())
2309enddef
2310
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002311def Test_setcmdpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002312 CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002313enddef
2314
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002315def Test_setfperm()
2316 CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2317 CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
2318enddef
2319
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002320def Test_setbufline()
2321 new
2322 var bnum = bufnr('%')
2323 :wincmd w
2324 setbufline(bnum, 1, range(1, 3))
2325 setbufline(bnum, 4, 'one')
2326 setbufline(bnum, 5, 10)
2327 setbufline(bnum, 6, ['two', 11])
2328 assert_equal(['1', '2', '3', 'one', '10', 'two', '11'], getbufline(bnum, 1, '$'))
2329 CheckDefFailure(['setbufline([1], 1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>')
2330 CheckDefFailure(['setbufline(1, [1], "x")'], 'E1013: Argument 2: type mismatch, expected string but got list<number>')
2331 CheckDefFailure(['setbufline(1, 1, {"a": 10})'], 'E1013: Argument 3: type mismatch, expected string but got dict<number>')
2332 bnum->bufwinid()->win_gotoid()
2333 bw!
2334enddef
2335
2336def Test_setcellwidths()
2337 CheckDefAndScriptFailure2(['setcellwidths(1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E714: List required')
2338 CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2339enddef
2340
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002341def Test_setline()
2342 new
2343 setline(1, range(1, 4))
2344 assert_equal(['1', '2', '3', '4'], getline(1, '$'))
2345 setline(1, ['a', 'b', 'c', 'd'])
2346 assert_equal(['a', 'b', 'c', 'd'], getline(1, '$'))
2347 setline(1, 'one')
2348 assert_equal(['one', 'b', 'c', 'd'], getline(1, '$'))
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002349 setline(1, 10)
2350 assert_equal(['10', 'b', 'c', 'd'], getline(1, '$'))
2351 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 +02002352 bw!
2353enddef
2354
Bram Moolenaar94738d82020-10-21 14:25:07 +02002355def Test_setloclist()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002356 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
2357 var what = {items: items}
Bram Moolenaar94738d82020-10-21 14:25:07 +02002358 setqflist([], ' ', what)
2359 setloclist(0, [], ' ', what)
2360enddef
2361
2362def Test_setreg()
2363 setreg('a', ['aaa', 'bbb', 'ccc'])
2364 var reginfo = getreginfo('a')
2365 setreg('a', reginfo)
2366 getreginfo('a')->assert_equal(reginfo)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01002367 assert_fails('setreg("ab", 0)', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002368enddef
2369
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002370def Test_sha256()
2371 CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2372 CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
2373 assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc'))
2374enddef
2375
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002376def Test_shiftwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002377 CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2378enddef
2379
2380def Test_sign_define()
2381 CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2382 CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2383 CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
2384enddef
2385
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002386def Test_sign_getdefined()
2387 CheckDefAndScriptFailure2(['sign_getdefined(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
2388 CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2389enddef
2390
2391def Test_sign_placelist()
2392 CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2393 CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2394enddef
2395
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002396def Test_sign_undefine()
2397 CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2398 CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:')
2399enddef
2400
2401def Test_sign_unplace()
2402 CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2403 CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2404 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 +02002405enddef
2406
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002407def Test_sign_unplacelist()
2408 CheckDefAndScriptFailure2(['sign_unplacelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2409 CheckDefAndScriptFailure2(['sign_unplacelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2410enddef
2411
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002412def Test_simplify()
2413 CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2414 call assert_equal('NonExistingFile', simplify('NonExistingFile'))
2415enddef
2416
Bram Moolenaar6601b622021-01-13 21:47:15 +01002417def Test_slice()
2418 assert_equal('12345', slice('012345', 1))
2419 assert_equal('123', slice('012345', 1, 4))
2420 assert_equal('1234', slice('012345', 1, -1))
2421 assert_equal('1', slice('012345', 1, -4))
2422 assert_equal('', slice('012345', 1, -5))
2423 assert_equal('', slice('012345', 1, -6))
2424
2425 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
2426 assert_equal([1, 2, 3], slice(range(6), 1, 4))
2427 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
2428 assert_equal([1], slice(range(6), 1, -4))
2429 assert_equal([], slice(range(6), 1, -5))
2430 assert_equal([], slice(range(6), 1, -6))
2431
2432 assert_equal(0z1122334455, slice(0z001122334455, 1))
2433 assert_equal(0z112233, slice(0z001122334455, 1, 4))
2434 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
2435 assert_equal(0z11, slice(0z001122334455, 1, -4))
2436 assert_equal(0z, slice(0z001122334455, 1, -5))
2437 assert_equal(0z, slice(0z001122334455, 1, -6))
2438enddef
2439
Bram Moolenaar94738d82020-10-21 14:25:07 +02002440def Test_spellsuggest()
2441 if !has('spell')
2442 MissingFeature 'spell'
2443 else
2444 spellsuggest('marrch', 1, true)->assert_equal(['March'])
2445 endif
2446enddef
2447
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002448def Test_sound_stop()
2449 CheckFeature sound
2450 CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2451enddef
2452
2453def Test_soundfold()
2454 CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2455 assert_equal('abc', soundfold('abc'))
2456enddef
2457
Bram Moolenaar94738d82020-10-21 14:25:07 +02002458def Test_sort_return_type()
2459 var res: list<number>
2460 res = [1, 2, 3]->sort()
2461enddef
2462
2463def Test_sort_argument()
Bram Moolenaar08cf0c02020-12-05 21:47:06 +01002464 var lines =<< trim END
2465 var res = ['b', 'a', 'c']->sort('i')
2466 res->assert_equal(['a', 'b', 'c'])
2467
2468 def Compare(a: number, b: number): number
2469 return a - b
2470 enddef
2471 var l = [3, 6, 7, 1, 8, 2, 4, 5]
2472 sort(l, Compare)
2473 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
2474 END
2475 CheckDefAndScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002476enddef
2477
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002478def Test_spellbadword()
2479 CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2480 spellbadword('good')->assert_equal(['', ''])
2481enddef
2482
Bram Moolenaar94738d82020-10-21 14:25:07 +02002483def Test_split()
2484 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
2485enddef
2486
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002487def Test_srand()
2488 CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2489 type(srand(100))->assert_equal(v:t_list)
2490enddef
2491
2492def Test_state()
2493 CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2494 assert_equal('', state('a'))
2495enddef
2496
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002497def Run_str2float()
2498 if !has('float')
2499 MissingFeature 'float'
2500 endif
2501 str2float("1.00")->assert_equal(1.00)
2502 str2float("2e-2")->assert_equal(0.02)
2503
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002504 CheckDefFailure(['str2float(123)'], 'E1013:')
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002505 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
2506 endif
2507enddef
2508
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002509def Test_str2list()
2510 CheckDefAndScriptFailure2(['str2list(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2511 CheckDefAndScriptFailure2(['str2list("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
2512 assert_equal([97], str2list('a'))
2513 assert_equal([97], str2list('a', 1))
2514 assert_equal([97], str2list('a', true))
2515enddef
2516
Bram Moolenaar94738d82020-10-21 14:25:07 +02002517def Test_str2nr()
2518 str2nr("1'000'000", 10, true)->assert_equal(1000000)
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002519
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002520 CheckDefFailure(['str2nr(123)'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002521 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002522 CheckDefFailure(['str2nr("123", "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002523 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002524 CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002525 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002526enddef
2527
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002528def Test_strcharlen()
2529 CheckDefAndScriptFailure2(['strcharlen([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2530 "abc"->strcharlen()->assert_equal(3)
2531 strcharlen(99)->assert_equal(2)
2532enddef
2533
Bram Moolenaar94738d82020-10-21 14:25:07 +02002534def Test_strchars()
2535 strchars("A\u20dd", true)->assert_equal(1)
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002536 CheckDefAndScriptFailure2(['strchars(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2537 CheckDefAndScriptFailure2(['strchars("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
2538 assert_equal(3, strchars('abc'))
2539 assert_equal(3, strchars('abc', 1))
2540 assert_equal(3, strchars('abc', true))
Bram Moolenaar94738d82020-10-21 14:25:07 +02002541enddef
2542
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002543def Test_strdisplaywidth()
2544 CheckDefAndScriptFailure2(['strdisplaywidth(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2545 CheckDefAndScriptFailure2(['strdisplaywidth("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2546enddef
2547
2548def Test_strftime()
2549 CheckDefAndScriptFailure2(['strftime(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2550 CheckDefAndScriptFailure2(['strftime("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2551enddef
2552
2553def Test_strgetchar()
2554 CheckDefAndScriptFailure2(['strgetchar(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2555 CheckDefAndScriptFailure2(['strgetchar("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2556enddef
2557
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002558def Test_stridx()
2559 CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2560 CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2561 CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2562enddef
2563
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002564def Test_strlen()
2565 CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2566 "abc"->strlen()->assert_equal(3)
2567 strlen(99)->assert_equal(2)
2568enddef
2569
2570def Test_strptime()
2571 CheckFunction strptime
2572 CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2573 CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number')
2574 # BUG: Directly calling strptime() in this function gives an "E117: Unknown
2575 # function" error on MS-Windows even with the above CheckFunction call for
2576 # strptime().
2577 #assert_true(strptime('%Y', '2021') != 0)
2578enddef
2579
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002580def Test_strridx()
2581 CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2582 CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2583 CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2584enddef
2585
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002586def Test_strtrans()
2587 CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2588 assert_equal('abc', strtrans('abc'))
2589enddef
2590
2591def Test_strwidth()
2592 CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2593 CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:')
2594 assert_equal(4, strwidth('abcd'))
2595enddef
2596
Bram Moolenaar94738d82020-10-21 14:25:07 +02002597def Test_submatch()
2598 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
Bram Moolenaar75ab91f2021-01-10 22:42:50 +01002599 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
Bram Moolenaar94738d82020-10-21 14:25:07 +02002600 var actual = substitute('A123456789', pat, Rep, '')
2601 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
2602 actual->assert_equal(expected)
2603enddef
2604
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002605def Test_substitute()
2606 var res = substitute('A1234', '\d', 'X', '')
2607 assert_equal('AX234', res)
2608
2609 if has('job')
2610 assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job')
2611 assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel')
2612 endif
2613enddef
2614
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002615def Test_swapinfo()
2616 CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2617 call assert_equal({error: 'Cannot open file'}, swapinfo('x'))
2618enddef
2619
2620def Test_swapname()
2621 CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2622 assert_fails('swapname("NonExistingBuf")', 'E94:')
2623enddef
2624
Bram Moolenaar94738d82020-10-21 14:25:07 +02002625def Test_synID()
2626 new
2627 setline(1, "text")
2628 synID(1, 1, true)->assert_equal(0)
2629 bwipe!
2630enddef
2631
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002632def Test_synIDtrans()
2633 CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2634enddef
2635
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002636def Test_synconcealed()
2637 CheckDefAndScriptFailure2(['synconcealed(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2638 CheckDefAndScriptFailure2(['synconcealed(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2639enddef
2640
2641def Test_synstack()
2642 CheckDefAndScriptFailure2(['synstack(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2643 CheckDefAndScriptFailure2(['synstack(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2644enddef
2645
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002646def Test_tabpagebuflist()
2647 CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2648 assert_equal([bufnr('')], tabpagebuflist())
2649 assert_equal([bufnr('')], tabpagebuflist(1))
2650enddef
2651
2652def Test_tabpagenr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002653 CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002654 assert_equal(1, tabpagenr('$'))
2655 assert_equal(1, tabpagenr())
2656enddef
2657
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002658def Test_tabpagewinnr()
2659 CheckDefAndScriptFailure2(['tabpagewinnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2660 CheckDefAndScriptFailure2(['tabpagewinnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2661enddef
2662
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002663def Test_taglist()
2664 CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2665 CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2666enddef
2667
2668def Test_term_dumpload()
2669 CheckRunVimInTerminal
2670 CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2671 CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2672 CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2')
2673enddef
2674
2675def Test_term_getaltscreen()
2676 CheckRunVimInTerminal
2677 CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
2678enddef
2679
2680def Test_term_getansicolors()
2681 CheckRunVimInTerminal
Dominique Pelleee410522021-07-12 22:15:24 +02002682 CheckFeature termguicolors
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002683 CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number')
2684enddef
2685
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002686def Test_term_getattr()
2687 CheckRunVimInTerminal
2688 CheckDefAndScriptFailure2(['term_getattr("x", "a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2689 CheckDefAndScriptFailure2(['term_getattr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2690enddef
2691
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002692def Test_term_getcursor()
2693 CheckRunVimInTerminal
2694 CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number')
2695enddef
2696
2697def Test_term_getjob()
2698 CheckRunVimInTerminal
2699 CheckDefAndScriptFailure2(['term_getjob(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E974: Using a Blob as a Number')
2700enddef
2701
2702def Test_term_getscrolled()
2703 CheckRunVimInTerminal
2704 CheckDefAndScriptFailure2(['term_getscrolled(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2705enddef
2706
2707def Test_term_getsize()
2708 CheckRunVimInTerminal
2709 CheckDefAndScriptFailure2(['term_getsize(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2710enddef
2711
2712def Test_term_getstatus()
2713 CheckRunVimInTerminal
2714 CheckDefAndScriptFailure2(['term_getstatus(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2715enddef
2716
2717def Test_term_gettitle()
2718 CheckRunVimInTerminal
2719 CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2720enddef
2721
Bram Moolenaar94738d82020-10-21 14:25:07 +02002722def Test_term_gettty()
2723 if !has('terminal')
2724 MissingFeature 'terminal'
2725 else
2726 var buf = Run_shell_in_terminal({})
2727 term_gettty(buf, true)->assert_notequal('')
2728 StopShellInTerminal(buf)
2729 endif
2730enddef
2731
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002732def Test_term_sendkeys()
2733 CheckRunVimInTerminal
2734 CheckDefAndScriptFailure2(['term_sendkeys([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2735 CheckDefAndScriptFailure2(['term_sendkeys(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2736enddef
2737
2738def Test_term_setapi()
2739 CheckRunVimInTerminal
2740 CheckDefAndScriptFailure2(['term_setapi([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2741 CheckDefAndScriptFailure2(['term_setapi(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2742enddef
2743
2744def Test_term_setkill()
2745 CheckRunVimInTerminal
2746 CheckDefAndScriptFailure2(['term_setkill([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2747 CheckDefAndScriptFailure2(['term_setkill(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2748enddef
2749
2750def Test_term_setrestore()
2751 CheckRunVimInTerminal
2752 CheckDefAndScriptFailure2(['term_setrestore([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2753 CheckDefAndScriptFailure2(['term_setrestore(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2754enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02002755def Test_term_start()
2756 if !has('terminal')
2757 MissingFeature 'terminal'
2758 else
2759 botright new
2760 var winnr = winnr()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002761 term_start(&shell, {curwin: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002762 winnr()->assert_equal(winnr)
2763 bwipe!
2764 endif
2765enddef
2766
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002767def Test_term_wait()
2768 CheckRunVimInTerminal
2769 CheckDefAndScriptFailure2(['term_wait(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2770 CheckDefAndScriptFailure2(['term_wait(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2771enddef
2772
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002773def Test_test_alloc_fail()
2774 CheckDefAndScriptFailure2(['test_alloc_fail("a", 10, 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2775 CheckDefAndScriptFailure2(['test_alloc_fail(10, "b", 20)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2776 CheckDefAndScriptFailure2(['test_alloc_fail(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E474: Invalid argument')
2777enddef
2778
2779def Test_test_feedinput()
2780 CheckDefAndScriptFailure2(['test_feedinput(test_void())'], 'E1013: Argument 1: type mismatch, expected string but got void', 'E1031: Cannot use void value')
2781 CheckDefAndScriptFailure2(['test_feedinput(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2782enddef
2783
2784def Test_test_getvalue()
2785 CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument')
2786enddef
2787
2788def Test_test_ignore_error()
2789 CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2790 test_ignore_error('RESET')
2791enddef
2792
2793def Test_test_option_not_set()
2794 CheckDefAndScriptFailure2(['test_option_not_set([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2795enddef
2796
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002797def Test_test_override()
2798 CheckDefAndScriptFailure2(['test_override(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2799 CheckDefAndScriptFailure2(['test_override("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2800enddef
2801
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002802def Test_test_setmouse()
2803 CheckDefAndScriptFailure2(['test_setmouse("a", 10)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2804 CheckDefAndScriptFailure2(['test_setmouse(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2805enddef
2806
2807def Test_test_settime()
2808 CheckDefAndScriptFailure2(['test_settime([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2809enddef
2810
2811def Test_test_srand_seed()
2812 CheckDefAndScriptFailure2(['test_srand_seed([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2813 CheckDefAndScriptFailure2(['test_srand_seed("10")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2814enddef
2815
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002816def Test_timer_info()
2817 CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2818 assert_equal([], timer_info(100))
2819 assert_equal([], timer_info())
2820enddef
2821
Bram Moolenaar94738d82020-10-21 14:25:07 +02002822def Test_timer_paused()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002823 var id = timer_start(50, () => 0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002824 timer_pause(id, true)
2825 var info = timer_info(id)
2826 info[0]['paused']->assert_equal(1)
2827 timer_stop(id)
2828enddef
2829
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002830def Test_timer_stop()
2831 CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2832 assert_equal(0, timer_stop(100))
2833enddef
2834
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002835def Test_tolower()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002836 CheckDefFailure(['tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002837enddef
2838
2839def Test_toupper()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002840 CheckDefFailure(['toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002841enddef
2842
2843def Test_tr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002844 CheckDefFailure(['tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2845 CheckDefFailure(['tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
2846 CheckDefFailure(['tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
2847enddef
2848
2849def Test_trim()
2850 CheckDefAndScriptFailure2(['trim(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2851 CheckDefAndScriptFailure2(['trim("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2852 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 +02002853enddef
2854
Bram Moolenaar9da32e42021-07-09 19:53:57 +02002855def Test_typename()
2856 if has('float')
2857 assert_equal('func([unknown], [unknown]): float', typename(function('pow')))
2858 endif
2859enddef
2860
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002861def Test_undofile()
2862 CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2863 assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t'))
2864enddef
2865
2866def Test_values()
2867 CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2868 assert_equal([], {}->values())
2869 assert_equal(['sun'], {star: 'sun'}->values())
2870enddef
2871
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002872def Test_virtcol()
2873 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 +02002874 new
2875 setline(1, ['abcdefgh'])
2876 cursor(1, 4)
2877 assert_equal(4, virtcol('.'))
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02002878 assert_equal(4, virtcol([1, 4]))
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002879 assert_equal(9, virtcol([1, '$']))
2880 assert_equal(0, virtcol([10, '$']))
2881 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002882enddef
2883
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002884def Test_visualmode()
2885 CheckDefFailure(['visualmode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
2886 CheckDefFailure(['visualmode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
2887enddef
2888
Bram Moolenaar37487e12021-01-12 22:08:53 +01002889def Test_win_execute()
2890 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
Bram Moolenaar52312242021-07-11 18:23:19 +02002891 assert_equal("\n" .. winnr(), 'echo winnr()'->win_execute(win_getid()))
2892 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()', 'silent'))
Bram Moolenaar37487e12021-01-12 22:08:53 +01002893 assert_equal('', win_execute(342343, 'echo winnr()'))
2894enddef
2895
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002896def Test_win_findbuf()
2897 CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2898 assert_equal([], win_findbuf(1000))
2899 assert_equal([win_getid()], win_findbuf(bufnr('')))
2900enddef
2901
2902def Test_win_getid()
2903 CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2904 CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string')
2905 assert_equal(win_getid(), win_getid(1, 1))
2906enddef
2907
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002908def Test_win_gettype()
2909 CheckDefAndScriptFailure2(['win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2910enddef
2911
2912def Test_win_gotoid()
2913 CheckDefAndScriptFailure2(['win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2914enddef
2915
2916def Test_win_id2tabwin()
2917 CheckDefAndScriptFailure2(['win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2918enddef
2919
2920def Test_win_id2win()
2921 CheckDefAndScriptFailure2(['win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2922enddef
2923
2924def Test_win_screenpos()
2925 CheckDefAndScriptFailure2(['win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2926enddef
2927
Bram Moolenaar94738d82020-10-21 14:25:07 +02002928def Test_win_splitmove()
2929 split
Bram Moolenaare0de1712020-12-02 17:36:54 +01002930 win_splitmove(1, 2, {vertical: true, rightbelow: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002931 close
2932enddef
2933
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002934def Test_winbufnr()
2935 CheckDefAndScriptFailure2(['winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2936enddef
2937
2938def Test_winheight()
2939 CheckDefAndScriptFailure2(['winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2940enddef
2941
2942def Test_winlayout()
2943 CheckDefAndScriptFailure2(['winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2944enddef
2945
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002946def Test_winnr()
2947 CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2948 assert_equal(1, winnr())
2949 assert_equal(1, winnr('$'))
2950enddef
2951
Bram Moolenaar285b15f2020-12-29 20:25:19 +01002952def Test_winrestcmd()
2953 split
2954 var cmd = winrestcmd()
2955 wincmd _
2956 exe cmd
2957 assert_equal(cmd, winrestcmd())
2958 close
2959enddef
2960
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002961def Test_winrestview()
2962 CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2963 :%d _
2964 setline(1, 'Hello World')
2965 winrestview({lnum: 1, col: 6})
2966 assert_equal([1, 7], [line('.'), col('.')])
2967enddef
2968
Bram Moolenaar43b69b32021-01-07 20:23:33 +01002969def Test_winsaveview()
2970 var view: dict<number> = winsaveview()
2971
2972 var lines =<< trim END
2973 var view: list<number> = winsaveview()
2974 END
2975 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
2976enddef
2977
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002978def Test_winwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002979 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 +02002980enddef
2981
2982def Test_xor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002983 CheckDefAndScriptFailure2(['xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2984 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 +02002985enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02002986
2987" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker