blob: f7c2f98ea18c9c15911a3414aa1c318da376b5e7 [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:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100476enddef
477
478def Test_charclass()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200479 assert_fails('charclass(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100480enddef
481
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200482def Test_charcol()
483 CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
484 CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200485 new
486 setline(1, ['abcdefgh'])
487 cursor(1, 4)
488 assert_equal(4, charcol('.'))
489 assert_equal(9, charcol([1, '$']))
490 assert_equal(0, charcol([10, '$']))
491 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200492enddef
493
494def Test_charidx()
495 CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string')
496 CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
497 CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string')
498enddef
499
Bram Moolenaarc5809432021-03-27 21:23:30 +0100500def Test_chdir()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200501 assert_fails('chdir(true)', 'E1174:')
502enddef
503
504def Test_cindent()
505 CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
506 CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
507 assert_equal(-1, cindent(0))
508 assert_equal(0, cindent('.'))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200509enddef
510
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200511def Test_clearmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200512 CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200513enddef
514
Bram Moolenaar94738d82020-10-21 14:25:07 +0200515def Test_col()
516 new
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200517 setline(1, 'abcdefgh')
518 cursor(1, 4)
519 assert_equal(4, col('.'))
520 col([1, '$'])->assert_equal(9)
521 assert_equal(0, col([10, '$']))
Bram Moolenaarc5809432021-03-27 21:23:30 +0100522
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200523 assert_fails('col(true)', 'E1174:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200524
525 CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
526 CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
527 CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
528 bw!
Bram Moolenaarc5809432021-03-27 21:23:30 +0100529enddef
530
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200531def Test_complete_info()
532 CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
533 CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>')
534 assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info())
535 assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items']))
536enddef
537
Bram Moolenaarc5809432021-03-27 21:23:30 +0100538def Test_confirm()
539 if !has('dialog_con') && !has('dialog_gui')
540 CheckFeature dialog_con
541 endif
542
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200543 assert_fails('confirm(true)', 'E1174:')
544 assert_fails('confirm("yes", true)', 'E1174:')
545 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:')
546enddef
547
Bram Moolenaar94738d82020-10-21 14:25:07 +0200548def Test_copy_return_type()
549 var l = copy([1, 2, 3])
550 var res = 0
551 for n in l
552 res += n
553 endfor
554 res->assert_equal(6)
555
556 var dl = deepcopy([1, 2, 3])
557 res = 0
558 for n in dl
559 res += n
560 endfor
561 res->assert_equal(6)
562
563 dl = deepcopy([1, 2, 3], true)
564enddef
565
566def Test_count()
567 count('ABC ABC ABC', 'b', true)->assert_equal(3)
568 count('ABC ABC ABC', 'b', false)->assert_equal(0)
569enddef
570
Bram Moolenaar9a963372020-12-21 21:58:46 +0100571def Test_cursor()
572 new
573 setline(1, range(4))
574 cursor(2, 1)
575 assert_equal(2, getcurpos()[1])
576 cursor('$', 1)
577 assert_equal(4, getcurpos()[1])
578
579 var lines =<< trim END
580 cursor('2', 1)
581 END
Bram Moolenaar0f1227f2021-07-11 16:01:58 +0200582 CheckDefExecAndScriptFailure(lines, 'E1209:')
Bram Moolenaar9a963372020-12-21 21:58:46 +0100583enddef
584
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200585def Test_debugbreak()
586 CheckMSWindows
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200587 CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200588enddef
589
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100590def Test_delete()
591 var res: bool = delete('doesnotexist')
592 assert_equal(true, res)
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200593
594 CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
595 CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100596enddef
597
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200598def Test_diff_filler()
599 CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
600 CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
601 assert_equal(0, diff_filler(1))
602 assert_equal(0, diff_filler('.'))
603enddef
604
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200605def Test_echoraw()
606 CheckDefAndScriptFailure2(['echoraw(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
607 CheckDefAndScriptFailure2(['echoraw(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
608enddef
609
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200610def Test_escape()
611 CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
612 CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number')
613 CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
614 assert_equal('a\:b', escape("a:b", ":"))
615enddef
616
617def Test_eval()
618 CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
619 CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
620 assert_equal(2, eval('1 + 1'))
621enddef
622
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100623def Test_executable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100624 assert_false(executable(""))
625 assert_false(executable(test_null_string()))
626
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200627 CheckDefExecFailure(['echo executable(123)'], 'E1013:')
628 CheckDefExecFailure(['echo executable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100629enddef
630
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200631def Test_execute()
632 var res = execute("echo 'hello'")
633 assert_equal("\nhello", res)
634 res = execute(["echo 'here'", "echo 'there'"])
635 assert_equal("\nhere\nthere", res)
636
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200637 CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
638 CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200639 CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200640 CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200641enddef
642
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100643def Test_exepath()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200644 CheckDefExecFailure(['echo exepath(true)'], 'E1013:')
645 CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100646 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100647enddef
648
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200649def Test_exists()
650 CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
651 call assert_equal(1, exists('&tabstop'))
652enddef
653
Bram Moolenaar94738d82020-10-21 14:25:07 +0200654def Test_expand()
655 split SomeFile
656 expand('%', true, true)->assert_equal(['SomeFile'])
657 close
658enddef
659
Bram Moolenaar02795102021-05-03 21:40:26 +0200660def Test_expandcmd()
661 $FOO = "blue"
662 assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
663
664 assert_equal("yes", expandcmd("`={a: 'yes'}['a']`"))
665enddef
666
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100667def Test_extend_arg_types()
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100668 g:number_one = 1
669 g:string_keep = 'keep'
670 var lines =<< trim END
671 assert_equal([1, 2, 3], extend([1, 2], [3]))
672 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
673 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
674 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100675
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100676 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
677 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
678 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
679 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100680
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100681 var res: list<dict<any>>
682 extend(res, mapnew([1, 2], (_, v) => ({})))
683 assert_equal([{}, {}], res)
684 END
685 CheckDefAndScriptSuccess(lines)
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100686
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200687 CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100688 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
689 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
690 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
691
Bram Moolenaare0de1712020-12-02 17:36:54 +0100692 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
693 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
694 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
Bram Moolenaar351ead02021-01-16 16:07:01 +0100695
696 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
Bram Moolenaare32e5162021-01-21 20:21:29 +0100697 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100698enddef
699
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100700func g:ExtendDict(d)
701 call extend(a:d, #{xx: 'x'})
702endfunc
703
704def Test_extend_dict_item_type()
705 var lines =<< trim END
706 var d: dict<number> = {a: 1}
707 extend(d, {b: 2})
708 END
709 CheckDefAndScriptSuccess(lines)
710
711 lines =<< trim END
712 var d: dict<number> = {a: 1}
713 extend(d, {b: 'x'})
714 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100715 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100716
717 lines =<< trim END
718 var d: dict<number> = {a: 1}
719 g:ExtendDict(d)
720 END
721 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
722 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
723enddef
724
725func g:ExtendList(l)
726 call extend(a:l, ['x'])
727endfunc
728
729def Test_extend_list_item_type()
730 var lines =<< trim END
731 var l: list<number> = [1]
732 extend(l, [2])
733 END
734 CheckDefAndScriptSuccess(lines)
735
736 lines =<< trim END
737 var l: list<number> = [1]
738 extend(l, ['x'])
739 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100740 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100741
742 lines =<< trim END
743 var l: list<number> = [1]
744 g:ExtendList(l)
745 END
746 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
747 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
748enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200749
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200750def Test_extend_return_type()
751 var l = extend([1, 2], [3])
752 var res = 0
753 for n in l
754 res += n
755 endfor
756 res->assert_equal(6)
757enddef
758
Bram Moolenaar93e1cae2021-03-13 21:24:56 +0100759def Test_extend_with_error_function()
760 var lines =<< trim END
761 vim9script
762 def F()
763 {
764 var m = 10
765 }
766 echo m
767 enddef
768
769 def Test()
770 var d: dict<any> = {}
771 d->extend({A: 10, Func: function('F', [])})
772 enddef
773
774 Test()
775 END
776 CheckScriptFailure(lines, 'E1001: Variable not found: m')
777enddef
778
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200779def Test_extendnew()
780 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
781 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
782
783 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
784 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
785 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
786 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
787enddef
788
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200789def Test_feedkeys()
790 CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
791 CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
792 CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
793 g:TestVar = 1
794 feedkeys(":g:TestVar = 789\n", 'xt')
795 assert_equal(789, g:TestVar)
796 unlet g:TestVar
797enddef
798
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100799def Test_filereadable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100800 assert_false(filereadable(""))
801 assert_false(filereadable(test_null_string()))
802
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200803 CheckDefExecFailure(['echo filereadable(123)'], 'E1013:')
804 CheckDefExecFailure(['echo filereadable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100805enddef
806
807def Test_filewritable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100808 assert_false(filewritable(""))
809 assert_false(filewritable(test_null_string()))
810
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200811 CheckDefExecFailure(['echo filewritable(123)'], 'E1013:')
812 CheckDefExecFailure(['echo filewritable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100813enddef
814
815def Test_finddir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200816 CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
817 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 +0100818 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200819 CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
820 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 +0100821enddef
822
823def Test_findfile()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200824 CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
825 CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
826 CheckDefExecFailure(['findfile("")'], 'E1175:')
827 CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
828 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 +0100829enddef
830
Bram Moolenaar3b690062021-02-01 20:14:51 +0100831def Test_flattennew()
832 var lines =<< trim END
833 var l = [1, [2, [3, 4]], 5]
834 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
835 call assert_equal([1, [2, [3, 4]], 5], l)
836
837 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
838 call assert_equal([1, [2, [3, 4]], 5], l)
839 END
840 CheckDefAndScriptSuccess(lines)
841
842 lines =<< trim END
843 echo flatten([1, 2, 3])
844 END
845 CheckDefAndScriptFailure(lines, 'E1158:')
846enddef
847
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200848" Test for float functions argument type
849def Test_float_funcs_args()
850 CheckFeature float
851
852 # acos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200853 CheckDefFailure(['acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200854 # asin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200855 CheckDefFailure(['asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200856 # atan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200857 CheckDefFailure(['atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200858 # atan2()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200859 CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
860 CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
861 CheckDefFailure(['atan2(1.2)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200862 # ceil()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200863 CheckDefFailure(['ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200864 # cos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200865 CheckDefFailure(['cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200866 # cosh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200867 CheckDefFailure(['cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200868 # exp()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200869 CheckDefFailure(['exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200870 # float2nr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200871 CheckDefFailure(['float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200872 # floor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200873 CheckDefFailure(['floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200874 # fmod()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200875 CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
876 CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
877 CheckDefFailure(['fmod(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200878 # isinf()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200879 CheckDefFailure(['isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200880 # isnan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200881 CheckDefFailure(['isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200882 # log()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200883 CheckDefFailure(['log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200884 # log10()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200885 CheckDefFailure(['log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200886 # pow()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200887 CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
888 CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
889 CheckDefFailure(['pow(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200890 # round()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200891 CheckDefFailure(['round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200892 # sin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200893 CheckDefFailure(['sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200894 # sinh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200895 CheckDefFailure(['sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200896 # sqrt()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200897 CheckDefFailure(['sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200898 # tan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200899 CheckDefFailure(['tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200900 # tanh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200901 CheckDefFailure(['tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200902 # trunc()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200903 CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200904enddef
905
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200906def Test_fnameescape()
907 CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
908 assert_equal('\+a\%b\|', fnameescape('+a%b|'))
909enddef
910
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100911def Test_fnamemodify()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100912 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
913 CheckDefSuccess(['echo fnamemodify("", ":p")'])
914 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
915 CheckDefSuccess(['echo fnamemodify("file", "")'])
916
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200917 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool')
918 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special')
919 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100920enddef
921
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100922def Wrong_dict_key_type(items: list<number>): list<number>
923 return filter(items, (_, val) => get({[val]: 1}, 'x'))
924enddef
925
Bram Moolenaar94738d82020-10-21 14:25:07 +0200926def Test_filter_wrong_dict_key_type()
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100927 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200928enddef
929
930def Test_filter_return_type()
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200931 var l = filter([1, 2, 3], (_, _) => 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200932 var res = 0
933 for n in l
934 res += n
935 endfor
936 res->assert_equal(6)
937enddef
938
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100939def Test_filter_missing_argument()
940 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200941 var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100942 res->assert_equal({aa: [1], ac: [3]})
943enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200944
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200945def Test_foldclosed()
946 CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any')
947 assert_equal(-1, foldclosed(1))
948 assert_equal(-1, foldclosed('$'))
949enddef
950
951def Test_foldclosedend()
952 CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
953 assert_equal(-1, foldclosedend(1))
954 assert_equal(-1, foldclosedend('w0'))
955enddef
956
957def Test_foldlevel()
958 CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
959 assert_equal(0, foldlevel(1))
960 assert_equal(0, foldlevel('.'))
961enddef
962
963def Test_foldtextresult()
964 CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
965 assert_equal('', foldtextresult(1))
966 assert_equal('', foldtextresult('.'))
967enddef
968
Bram Moolenaar7d840e92021-05-26 21:10:11 +0200969def Test_fullcommand()
970 assert_equal('next', fullcommand('n'))
971 assert_equal('noremap', fullcommand('no'))
972 assert_equal('noremap', fullcommand('nor'))
973 assert_equal('normal', fullcommand('norm'))
974
975 assert_equal('', fullcommand('k'))
976 assert_equal('keepmarks', fullcommand('ke'))
977 assert_equal('keepmarks', fullcommand('kee'))
978 assert_equal('keepmarks', fullcommand('keep'))
979 assert_equal('keepjumps', fullcommand('keepj'))
980
981 assert_equal('dlist', fullcommand('dl'))
982 assert_equal('', fullcommand('dp'))
983 assert_equal('delete', fullcommand('del'))
984 assert_equal('', fullcommand('dell'))
985 assert_equal('', fullcommand('delp'))
986
987 assert_equal('srewind', fullcommand('sre'))
988 assert_equal('scriptnames', fullcommand('scr'))
989 assert_equal('', fullcommand('scg'))
990enddef
991
Bram Moolenaar94738d82020-10-21 14:25:07 +0200992def Test_garbagecollect()
993 garbagecollect(true)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200994 CheckDefAndScriptFailure2(['garbagecollect("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
995 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 +0200996enddef
997
998def Test_getbufinfo()
999 var bufinfo = getbufinfo(bufnr())
1000 getbufinfo('%')->assert_equal(bufinfo)
1001
1002 edit Xtestfile1
1003 hide edit Xtestfile2
1004 hide enew
Bram Moolenaare0de1712020-12-02 17:36:54 +01001005 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001006 ->len()->assert_equal(3)
1007 bwipe Xtestfile1 Xtestfile2
1008enddef
1009
1010def Test_getbufline()
1011 e SomeFile
1012 var buf = bufnr()
1013 e #
1014 var lines = ['aaa', 'bbb', 'ccc']
1015 setbufline(buf, 1, lines)
1016 getbufline('#', 1, '$')->assert_equal(lines)
Bram Moolenaare6e70a12020-10-22 18:23:38 +02001017 getbufline(-1, '$', '$')->assert_equal([])
1018 getbufline(-1, 1, '$')->assert_equal([])
Bram Moolenaar94738d82020-10-21 14:25:07 +02001019
1020 bwipe!
1021enddef
1022
1023def Test_getchangelist()
1024 new
1025 setline(1, 'some text')
1026 var changelist = bufnr()->getchangelist()
1027 getchangelist('%')->assert_equal(changelist)
1028 bwipe!
1029enddef
1030
1031def Test_getchar()
1032 while getchar(0)
1033 endwhile
1034 getchar(true)->assert_equal(0)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001035 getchar(1)->assert_equal(0)
1036 CheckDefAndScriptFailure2(['getchar(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1037 CheckDefAndScriptFailure2(['getchar("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
1038enddef
1039
1040def Test_getcharpos()
1041 CheckDefAndScriptFailure2(['getcharpos(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1042 CheckDefAndScriptFailure2(['getcharpos(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1043enddef
1044
1045def Test_getcharstr()
1046 CheckDefAndScriptFailure2(['getcharstr(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1047 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 +02001048enddef
1049
Bram Moolenaar7ad67d12021-03-10 16:08:26 +01001050def Test_getenv()
1051 if getenv('does-not_exist') == ''
1052 assert_report('getenv() should return null')
1053 endif
1054 if getenv('does-not_exist') == null
1055 else
1056 assert_report('getenv() should return null')
1057 endif
1058 $SOMEENVVAR = 'some'
1059 assert_equal('some', getenv('SOMEENVVAR'))
1060 unlet $SOMEENVVAR
1061enddef
1062
Bram Moolenaar94738d82020-10-21 14:25:07 +02001063def Test_getcompletion()
1064 set wildignore=*.vim,*~
1065 var l = getcompletion('run', 'file', true)
1066 l->assert_equal([])
1067 set wildignore&
1068enddef
1069
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001070def Test_getcurpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001071 CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001072enddef
1073
1074def Test_getcursorcharpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001075 CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001076enddef
1077
1078def Test_getcwd()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001079 CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1080 CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1081 CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001082enddef
1083
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001084def Test_getfontname()
1085 CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1086enddef
1087
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001088def Test_getfperm()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001089 assert_equal('', getfperm(""))
1090 assert_equal('', getfperm(test_null_string()))
1091
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001092 CheckDefExecFailure(['echo getfperm(true)'], 'E1013:')
1093 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001094enddef
1095
1096def Test_getfsize()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001097 assert_equal(-1, getfsize(""))
1098 assert_equal(-1, getfsize(test_null_string()))
1099
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001100 CheckDefExecFailure(['echo getfsize(true)'], 'E1013:')
1101 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001102enddef
1103
1104def Test_getftime()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001105 assert_equal(-1, getftime(""))
1106 assert_equal(-1, getftime(test_null_string()))
1107
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001108 CheckDefExecFailure(['echo getftime(true)'], 'E1013:')
1109 CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001110enddef
1111
1112def Test_getftype()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001113 assert_equal('', getftype(""))
1114 assert_equal('', getftype(test_null_string()))
1115
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001116 CheckDefExecFailure(['echo getftype(true)'], 'E1013:')
1117 CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001118enddef
1119
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001120def Test_getjumplist()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001121 CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1122 CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1123 CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001124enddef
1125
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001126def Test_getline()
1127 var lines =<< trim END
1128 new
1129 setline(1, ['hello', 'there', 'again'])
1130 assert_equal('hello', getline(1))
1131 assert_equal('hello', getline('.'))
1132
1133 normal 2Gvjv
1134 assert_equal('there', getline("'<"))
1135 assert_equal('again', getline("'>"))
1136 END
1137 CheckDefAndScriptSuccess(lines)
1138
1139 lines =<< trim END
1140 echo getline('1')
1141 END
1142 CheckDefExecAndScriptFailure(lines, 'E1209:')
1143enddef
1144
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001145def Test_getloclist()
1146 CheckDefAndScriptFailure2(['getloclist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1147 CheckDefAndScriptFailure2(['getloclist(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
1148enddef
1149
1150def Test_getloclist_return_type()
1151 var l = getloclist(1)
1152 l->assert_equal([])
1153
1154 var d = getloclist(1, {items: 0})
1155 d->assert_equal({items: []})
1156enddef
1157
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001158def Test_getmarklist()
1159 CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1160 assert_equal([], getmarklist(10000))
1161 assert_fails('getmarklist("a%b@#")', 'E94:')
1162enddef
1163
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001164def Test_getmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001165 CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001166enddef
1167
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001168def Test_getpos()
1169 CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1170 assert_equal([0, 1, 1, 0], getpos('.'))
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001171 CheckDefExecFailure(['getpos("a")'], 'E1209:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001172enddef
1173
1174def Test_getqflist()
1175 CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1176 call assert_equal({}, getqflist({}))
1177enddef
1178
Bram Moolenaar94738d82020-10-21 14:25:07 +02001179def Test_getqflist_return_type()
1180 var l = getqflist()
1181 l->assert_equal([])
1182
Bram Moolenaare0de1712020-12-02 17:36:54 +01001183 var d = getqflist({items: 0})
1184 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001185enddef
1186
1187def Test_getreg()
1188 var lines = ['aaa', 'bbb', 'ccc']
1189 setreg('a', lines)
1190 getreg('a', true, true)->assert_equal(lines)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001191 assert_fails('getreg("ab")', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001192enddef
1193
1194def Test_getreg_return_type()
1195 var s1: string = getreg('"')
1196 var s2: string = getreg('"', 1)
1197 var s3: list<string> = getreg('"', 1, 1)
1198enddef
1199
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001200def Test_getreginfo()
1201 var text = 'abc'
1202 setreg('a', text)
1203 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
1204 assert_fails('getreginfo("ab")', 'E1162:')
1205enddef
1206
1207def Test_getregtype()
1208 var lines = ['aaa', 'bbb', 'ccc']
1209 setreg('a', lines)
1210 getregtype('a')->assert_equal('V')
1211 assert_fails('getregtype("ab")', 'E1162:')
1212enddef
1213
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001214def Test_gettabinfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001215 CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001216enddef
1217
1218def Test_gettagstack()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001219 CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001220enddef
1221
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001222def Test_gettext()
1223 CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1224 assert_equal('abc', gettext("abc"))
1225enddef
1226
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001227def Test_getwininfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001228 CheckDefFailure(['getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001229enddef
1230
1231def Test_getwinpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001232 CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001233enddef
1234
Bram Moolenaar94738d82020-10-21 14:25:07 +02001235def Test_glob()
1236 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
1237enddef
1238
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001239def Test_glob2regpat()
1240 CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1241 assert_equal('^$', glob2regpat(''))
1242enddef
1243
Bram Moolenaar94738d82020-10-21 14:25:07 +02001244def Test_globpath()
1245 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
1246enddef
1247
1248def Test_has()
1249 has('eval', true)->assert_equal(1)
1250enddef
1251
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001252def Test_has_key()
Bram Moolenaar1aeddeb2021-07-11 14:55:49 +02001253 var d = {123: 'xx'}
1254 assert_true(has_key(d, '123'))
1255 assert_true(has_key(d, 123))
1256 assert_false(has_key(d, 'x'))
1257 assert_false(has_key(d, 99))
1258
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001259 CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1260 CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1261enddef
1262
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001263def Test_haslocaldir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001264 CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1265 CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1266 CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001267enddef
1268
Bram Moolenaar94738d82020-10-21 14:25:07 +02001269def Test_hasmapto()
1270 hasmapto('foobar', 'i', true)->assert_equal(0)
1271 iabbrev foo foobar
1272 hasmapto('foobar', 'i', true)->assert_equal(1)
1273 iunabbrev foo
1274enddef
1275
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001276def Test_histadd()
1277 CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1278 CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1279 histadd("search", 'skyblue')
1280 assert_equal('skyblue', histget('/', -1))
1281enddef
1282
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001283def Test_histget()
1284 CheckDefAndScriptFailure2(['histget(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1285 CheckDefAndScriptFailure2(['histget("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1286enddef
1287
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001288def Test_histnr()
1289 CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1290 assert_equal(-1, histnr('abc'))
1291enddef
1292
1293def Test_hlID()
1294 CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1295 assert_equal(0, hlID('NonExistingHighlight'))
1296enddef
1297
1298def Test_hlexists()
1299 CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1300 assert_equal(0, hlexists('NonExistingHighlight'))
1301enddef
1302
1303def Test_iconv()
1304 CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1305 CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1306 CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1307 assert_equal('abc', iconv('abc', 'fromenc', 'toenc'))
1308enddef
1309
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001310def Test_indent()
1311 CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number')
1312 CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
1313 assert_equal(0, indent(1))
1314enddef
1315
Bram Moolenaar94738d82020-10-21 14:25:07 +02001316def Test_index()
1317 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
1318enddef
1319
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001320def Test_input()
1321 CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1322 CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1323 CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1324 CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value')
1325enddef
1326
1327def Test_inputdialog()
1328 CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1329 CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1330 CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1331 CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1332enddef
1333
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001334def Test_inputlist()
1335 CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number')
1336 CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
1337 CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
1338 feedkeys("2\<CR>", 't')
1339 var r: number = inputlist(['a', 'b', 'c'])
1340 assert_equal(2, r)
1341enddef
1342
1343def Test_inputsecret()
1344 CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1345 CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1346 feedkeys("\<CR>", 't')
1347 var ans: string = inputsecret('Pass:', '123')
1348 assert_equal('123', ans)
1349enddef
1350
Bram Moolenaar193f6202020-11-16 20:08:35 +01001351let s:number_one = 1
1352let s:number_two = 2
1353let s:string_keep = 'keep'
1354
Bram Moolenaarca174532020-10-21 16:42:22 +02001355def Test_insert()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001356 var l = insert([2, 1], 3)
1357 var res = 0
1358 for n in l
1359 res += n
1360 endfor
1361 res->assert_equal(6)
Bram Moolenaarca174532020-10-21 16:42:22 +02001362
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001363 var m: any = []
1364 insert(m, 4)
1365 call assert_equal([4], m)
1366 extend(m, [6], 0)
1367 call assert_equal([6, 4], m)
1368
Bram Moolenaar39211cb2021-04-18 15:48:04 +02001369 var lines =<< trim END
1370 insert(test_null_list(), 123)
1371 END
1372 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
1373
1374 lines =<< trim END
1375 insert(test_null_blob(), 123)
1376 END
1377 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
1378
Bram Moolenaarca174532020-10-21 16:42:22 +02001379 assert_equal([1, 2, 3], insert([2, 3], 1))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001380 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
Bram Moolenaarca174532020-10-21 16:42:22 +02001381 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001382 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
Bram Moolenaarca174532020-10-21 16:42:22 +02001383 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
1384 assert_equal(0z1234, insert(0z34, 0x12))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001385
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001386 CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
Bram Moolenaarca174532020-10-21 16:42:22 +02001387 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
1388 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001389enddef
1390
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001391def Test_invert()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001392 CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001393enddef
1394
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001395def Test_isdirectory()
1396 CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
1397 assert_false(isdirectory('NonExistingDir'))
1398enddef
1399
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001400def Test_islocked()
1401 CheckDefAndScriptFailure2(['islocked(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1402 CheckDefAndScriptFailure2(['var n1: number = 10', 'islocked(n1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1403 g:v1 = 10
1404 assert_false(islocked('g:v1'))
1405 lockvar g:v1
1406 assert_true(islocked('g:v1'))
1407 unlet g:v1
1408enddef
1409
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001410def Test_items()
1411 CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1412 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items())
1413 assert_equal([], {}->items())
1414enddef
1415
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001416def Test_job_getchannel()
1417 CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1418 assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job')
1419enddef
1420
1421def Test_job_info()
1422 CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1423 assert_fails('job_info(test_null_job())', 'E916: not a valid job')
1424enddef
1425
1426def Test_job_info_return_type()
1427 if has('job')
1428 job_start(&shell)
1429 var jobs = job_info()
1430 assert_equal('list<job>', typename(jobs))
1431 assert_equal('dict<any>', typename(job_info(jobs[0])))
1432 job_stop(jobs[0])
1433 endif
1434enddef
1435
1436def Test_job_status()
1437 CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1438 assert_equal('fail', job_status(test_null_job()))
1439enddef
1440
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001441def Test_js_decode()
1442 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1443 assert_equal([1, 2], js_decode('[1,2]'))
1444enddef
1445
1446def Test_json_decode()
1447 CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1448 assert_equal(1.0, json_decode('1.0'))
1449enddef
1450
1451def Test_keys()
1452 CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1453 assert_equal(['a'], {a: 'v'}->keys())
1454 assert_equal([], {}->keys())
1455enddef
1456
Bram Moolenaar94738d82020-10-21 14:25:07 +02001457def Test_keys_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001458 const var: list<string> = {a: 1, b: 2}->keys()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001459 var->assert_equal(['a', 'b'])
1460enddef
1461
Bram Moolenaarc5809432021-03-27 21:23:30 +01001462def Test_line()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001463 assert_fails('line(true)', 'E1174:')
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001464 CheckDefAndScriptFailure2(['line(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1465 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 +02001466enddef
1467
1468def Test_line2byte()
1469 CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1470 assert_equal(-1, line2byte(1))
1471 assert_equal(-1, line2byte(10000))
1472enddef
1473
1474def Test_lispindent()
1475 CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1476 assert_equal(0, lispindent(1))
Bram Moolenaarc5809432021-03-27 21:23:30 +01001477enddef
1478
Bram Moolenaar94738d82020-10-21 14:25:07 +02001479def Test_list2str_str2list_utf8()
1480 var s = "\u3042\u3044"
1481 var l = [0x3042, 0x3044]
1482 str2list(s, true)->assert_equal(l)
1483 list2str(l, true)->assert_equal(s)
1484enddef
1485
1486def SID(): number
1487 return expand('<SID>')
1488 ->matchstr('<SNR>\zs\d\+\ze_$')
1489 ->str2nr()
1490enddef
1491
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001492def Test_listener_flush()
1493 CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1494enddef
1495
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001496def Test_listener_remove()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001497 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 +02001498enddef
1499
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001500def Test_map_function_arg()
1501 var lines =<< trim END
1502 def MapOne(i: number, v: string): string
1503 return i .. ':' .. v
1504 enddef
1505 var l = ['a', 'b', 'c']
1506 map(l, MapOne)
1507 assert_equal(['0:a', '1:b', '2:c'], l)
1508 END
1509 CheckDefAndScriptSuccess(lines)
Bram Moolenaar8da6d6d2021-06-05 18:15:09 +02001510
1511 lines =<< trim END
1512 range(3)->map((a, b, c) => a + b + c)
1513 END
1514 CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
1515 lines =<< trim END
1516 range(3)->map((a, b, c, d) => a + b + c + d)
1517 END
1518 CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001519enddef
1520
1521def Test_map_item_type()
1522 var lines =<< trim END
1523 var l = ['a', 'b', 'c']
1524 map(l, (k, v) => k .. '/' .. v )
1525 assert_equal(['0/a', '1/b', '2/c'], l)
1526 END
1527 CheckDefAndScriptSuccess(lines)
1528
1529 lines =<< trim END
1530 var l: list<number> = [0]
1531 echo map(l, (_, v) => [])
1532 END
1533 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1534
1535 lines =<< trim END
1536 var l: list<number> = range(2)
1537 echo map(l, (_, v) => [])
1538 END
1539 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1540
1541 lines =<< trim END
1542 var d: dict<number> = {key: 0}
1543 echo map(d, (_, v) => [])
1544 END
1545 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1546enddef
1547
Bram Moolenaar94738d82020-10-21 14:25:07 +02001548def Test_maparg()
1549 var lnum = str2nr(expand('<sflnum>'))
1550 map foo bar
Bram Moolenaare0de1712020-12-02 17:36:54 +01001551 maparg('foo', '', false, true)->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001552 lnum: lnum + 1,
1553 script: 0,
1554 mode: ' ',
1555 silent: 0,
1556 noremap: 0,
1557 lhs: 'foo',
1558 lhsraw: 'foo',
1559 nowait: 0,
1560 expr: 0,
1561 sid: SID(),
1562 rhs: 'bar',
1563 buffer: 0})
1564 unmap foo
1565enddef
1566
1567def Test_mapcheck()
1568 iabbrev foo foobar
1569 mapcheck('foo', 'i', true)->assert_equal('foobar')
1570 iunabbrev foo
1571enddef
1572
1573def Test_maparg_mapset()
1574 nnoremap <F3> :echo "hit F3"<CR>
1575 var mapsave = maparg('<F3>', 'n', false, true)
1576 mapset('n', false, mapsave)
1577
1578 nunmap <F3>
1579enddef
1580
Bram Moolenaar027c4ab2021-02-21 16:20:18 +01001581def Test_map_failure()
1582 CheckFeature job
1583
1584 var lines =<< trim END
1585 vim9script
1586 writefile([], 'Xtmpfile')
1587 silent e Xtmpfile
1588 var d = {[bufnr('%')]: {a: 0}}
1589 au BufReadPost * Func()
1590 def Func()
1591 if d->has_key('')
1592 endif
1593 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
1594 enddef
1595 e
1596 END
1597 CheckScriptFailure(lines, 'E1013:')
1598 au! BufReadPost
1599 delete('Xtmpfile')
1600enddef
1601
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001602def Test_matcharg()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001603 CheckDefFailure(['matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001604enddef
1605
1606def Test_matchdelete()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001607 CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1608 CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1609 CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001610enddef
1611
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001612def Test_max()
1613 g:flag = true
1614 var l1: list<number> = g:flag
1615 ? [1, max([2, 3])]
1616 : [4, 5]
1617 assert_equal([1, 3], l1)
1618
1619 g:flag = false
1620 var l2: list<number> = g:flag
1621 ? [1, max([2, 3])]
1622 : [4, 5]
1623 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001624 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 +01001625enddef
1626
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001627def Test_menu_info()
1628 CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1629 CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1630 CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1631 assert_equal({}, menu_info('aMenu'))
1632enddef
1633
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001634def Test_min()
1635 g:flag = true
1636 var l1: list<number> = g:flag
1637 ? [1, min([2, 3])]
1638 : [4, 5]
1639 assert_equal([1, 2], l1)
1640
1641 g:flag = false
1642 var l2: list<number> = g:flag
1643 ? [1, min([2, 3])]
1644 : [4, 5]
1645 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001646 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 +01001647enddef
1648
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001649def Test_mkdir()
1650 CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1651 CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
1652 CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1653 delete('a', 'rf')
1654enddef
1655
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001656def Test_mode()
1657 CheckDefFailure(['mode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
1658 CheckDefFailure(['mode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
1659enddef
1660
1661def Test_mzeval()
1662 if !has('mzscheme')
1663 CheckFeature mzscheme
1664 endif
1665 CheckDefAndScriptFailure2(['mzscheme(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1666enddef
1667
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001668def Test_nextnonblank()
1669 CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1670 assert_equal(0, nextnonblank(1))
1671enddef
1672
Bram Moolenaar94738d82020-10-21 14:25:07 +02001673def Test_nr2char()
1674 nr2char(97, true)->assert_equal('a')
1675enddef
1676
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001677def Test_or()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001678 CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1679 CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1680enddef
1681
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001682def Test_pathshorten()
1683 CheckDefAndScriptFailure2(['pathshorten(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1684 CheckDefAndScriptFailure2(['pathshorten("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1685enddef
1686
1687def Test_perleval()
1688 if !has('perl')
1689 CheckFeature perl
1690 endif
1691 CheckDefAndScriptFailure2(['perleval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1692enddef
1693
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001694def Test_popup_atcursor()
1695 CheckDefAndScriptFailure2(['popup_atcursor({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1696 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 +02001697
1698 # Pass variable of type 'any' to popup_atcursor()
1699 var what: any = 'Hello'
1700 var popupID = what->popup_atcursor({moved: 'any'})
1701 assert_equal(0, popupID->popup_getoptions().tabpage)
1702 popupID->popup_close()
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001703enddef
1704
1705def Test_popup_beval()
1706 CheckDefAndScriptFailure2(['popup_beval({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1707 CheckDefAndScriptFailure2(['popup_beval("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1708enddef
1709
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001710def Test_popup_clear()
1711 CheckDefAndScriptFailure2(['popup_clear(["a"])'], 'E1013: Argument 1: type mismatch, expected bool but got list<string>', 'E745: Using a List as a Number')
1712 CheckDefAndScriptFailure2(['popup_clear(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1713enddef
1714
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02001715def Test_popup_create()
1716 # Pass variable of type 'any' to popup_create()
1717 var what: any = 'Hello'
1718 var popupID = what->popup_create({})
1719 assert_equal(0, popupID->popup_getoptions().tabpage)
1720 popupID->popup_close()
1721enddef
1722
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001723def Test_popup_dialog()
1724 CheckDefAndScriptFailure2(['popup_dialog({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1725 CheckDefAndScriptFailure2(['popup_dialog("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1726enddef
1727
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001728def Test_popup_filter_menu()
1729 CheckDefAndScriptFailure2(['popup_filter_menu("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1730 CheckDefAndScriptFailure2(['popup_filter_menu(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1731enddef
1732
1733def Test_popup_filter_yesno()
1734 CheckDefAndScriptFailure2(['popup_filter_yesno("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1735 CheckDefAndScriptFailure2(['popup_filter_yesno(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1736enddef
1737
1738def Test_popup_getoptions()
1739 CheckDefAndScriptFailure2(['popup_getoptions("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1740 CheckDefAndScriptFailure2(['popup_getoptions(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1741enddef
1742
1743def Test_popup_getpos()
1744 CheckDefAndScriptFailure2(['popup_getpos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1745 CheckDefAndScriptFailure2(['popup_getpos(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1746enddef
1747
1748def Test_popup_hide()
1749 CheckDefAndScriptFailure2(['popup_hide("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1750 CheckDefAndScriptFailure2(['popup_hide(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1751enddef
1752
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001753def Test_popup_locate()
1754 CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1755 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 +02001756enddef
1757
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001758def Test_popup_menu()
1759 CheckDefAndScriptFailure2(['popup_menu({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1760 CheckDefAndScriptFailure2(['popup_menu("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1761enddef
1762
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001763def Test_popup_move()
1764 CheckDefAndScriptFailure2(['popup_move("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1765 CheckDefAndScriptFailure2(['popup_move(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1766enddef
1767
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001768def Test_popup_notification()
1769 CheckDefAndScriptFailure2(['popup_notification({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1770 CheckDefAndScriptFailure2(['popup_notification("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1771enddef
1772
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001773def Test_popup_setoptions()
1774 CheckDefAndScriptFailure2(['popup_setoptions("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1775 CheckDefAndScriptFailure2(['popup_setoptions(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1776enddef
1777
1778def Test_popup_show()
1779 CheckDefAndScriptFailure2(['popup_show("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1780 CheckDefAndScriptFailure2(['popup_show(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1781enddef
1782
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001783def Test_prevnonblank()
1784 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1785 assert_equal(0, prevnonblank(1))
1786enddef
1787
1788def Test_prompt_getprompt()
Dominique Pelle74509232021-07-03 19:27:37 +02001789 if has('channel')
1790 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1791 assert_equal('', prompt_getprompt('NonExistingBuf'))
1792 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001793enddef
1794
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001795def Test_prop_find()
1796 CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1797 CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1798 CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1799enddef
1800
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001801def Test_prop_list()
1802 CheckDefAndScriptFailure2(['prop_list("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1803 CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1804enddef
1805
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001806def Test_prop_type_add()
1807 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')
1808 CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1809enddef
1810
1811def Test_prop_type_change()
1812 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')
1813 CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1814enddef
1815
1816def Test_prop_type_delete()
1817 CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1818 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')
1819 CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1820enddef
1821
1822def Test_prop_type_get()
1823 CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1824 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')
1825 CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1826enddef
1827
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001828def Test_prop_type_list()
1829 CheckDefAndScriptFailure2(['prop_type_list(["a"])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
1830 CheckDefAndScriptFailure2(['prop_type_list(2)'], 'E1013: Argument 1: type mismatch, expected dict<any> but got number', 'E715: Dictionary required')
1831enddef
1832
1833def Test_py3eval()
1834 if !has('python3')
1835 CheckFeature python3
1836 endif
1837 CheckDefAndScriptFailure2(['py3eval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1838enddef
1839
1840def Test_pyeval()
1841 if !has('python')
1842 CheckFeature python
1843 endif
1844 CheckDefAndScriptFailure2(['pyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1845enddef
1846
1847def Test_pyxeval()
1848 if !has('python') && !has('python3')
1849 CheckFeature python
1850 endif
1851 CheckDefAndScriptFailure2(['pyxeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1852enddef
1853
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001854def Test_rand()
1855 CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number')
1856 CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1857 assert_true(rand() >= 0)
1858 assert_true(rand(srand()) >= 0)
1859enddef
1860
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001861def Test_range()
1862 CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1863 CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1864 CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1865enddef
1866
Bram Moolenaar94738d82020-10-21 14:25:07 +02001867def Test_readdir()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001868 eval expand('sautest')->readdir((e) => e[0] !=# '.')
1869 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001870enddef
1871
Bram Moolenaarc423ad72021-01-13 20:38:03 +01001872def Test_readblob()
1873 var blob = 0z12341234
1874 writefile(blob, 'Xreadblob')
1875 var read: blob = readblob('Xreadblob')
1876 assert_equal(blob, read)
1877
1878 var lines =<< trim END
1879 var read: list<string> = readblob('Xreadblob')
1880 END
1881 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
1882 delete('Xreadblob')
1883enddef
1884
1885def Test_readfile()
1886 var text = ['aaa', 'bbb', 'ccc']
1887 writefile(text, 'Xreadfile')
1888 var read: list<string> = readfile('Xreadfile')
1889 assert_equal(text, read)
1890
1891 var lines =<< trim END
1892 var read: dict<string> = readfile('Xreadfile')
1893 END
1894 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
1895 delete('Xreadfile')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001896
1897 CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
1898 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 +01001899enddef
1900
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001901def Test_reltime()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02001902 CheckFeature reltime
1903
1904 CheckDefExecAndScriptFailure(['[]->reltime()'], 'E474:')
1905 CheckDefExecAndScriptFailure(['[]->reltime([])'], 'E474:')
1906
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001907 CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
1908 CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1909 CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
1910 CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
1911 var start: list<any> = reltime()
1912 assert_true(type(reltime(start)) == v:t_list)
1913 var end: list<any> = reltime()
1914 assert_true(type(reltime(start, end)) == v:t_list)
1915enddef
1916
1917def Test_reltimefloat()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02001918 CheckFeature reltime
1919
1920 CheckDefExecAndScriptFailure(['[]->reltimefloat()'], 'E474:')
1921
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001922 CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
1923 CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
1924 assert_true(type(reltimefloat(reltime())) == v:t_float)
1925enddef
1926
1927def Test_reltimestr()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02001928 CheckFeature reltime
1929
1930 CheckDefExecAndScriptFailure(['[]->reltimestr()'], 'E474:')
1931
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001932 CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
1933 CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
1934 assert_true(type(reltimestr(reltime())) == v:t_string)
1935enddef
1936
1937def Test_remote_foreground()
1938 CheckFeature clientserver
1939 # remote_foreground() doesn't fail on MS-Windows
1940 CheckNotMSWindows
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +02001941 CheckEnv DISPLAY
1942
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001943 CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1944 assert_fails('remote_foreground("NonExistingServer")', 'E241:')
1945enddef
1946
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001947def Test_remote_peek()
1948 CheckFeature clientserver
1949 CheckEnv DISPLAY
1950 CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
1951 CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used')
1952enddef
1953
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001954def Test_remote_read()
1955 CheckFeature clientserver
1956 CheckEnv DISPLAY
1957 CheckDefAndScriptFailure2(['remote_read(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1958 CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1959enddef
1960
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001961def Test_remote_startserver()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001962 CheckFeature clientserver
1963 CheckEnv DISPLAY
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001964 CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1965enddef
1966
Bram Moolenaar94738d82020-10-21 14:25:07 +02001967def Test_remove_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001968 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001969 var res = 0
1970 for n in l
1971 res += n
1972 endfor
1973 res->assert_equal(3)
1974enddef
1975
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001976def Test_rename()
1977 CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1978 CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1979enddef
1980
1981def Test_resolve()
1982 CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1983 assert_equal('SomeFile', resolve('SomeFile'))
1984enddef
1985
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001986def Test_reverse()
1987 CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E899: Argument of reverse() must be a List or Blob')
1988 CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E899: Argument of reverse() must be a List or Blob')
1989enddef
1990
Bram Moolenaar94738d82020-10-21 14:25:07 +02001991def Test_reverse_return_type()
1992 var l = reverse([1, 2, 3])
1993 var res = 0
1994 for n in l
1995 res += n
1996 endfor
1997 res->assert_equal(6)
1998enddef
1999
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002000def Test_rubyeval()
2001 if !has('ruby')
2002 CheckFeature ruby
2003 endif
2004 CheckDefAndScriptFailure2(['rubyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2005enddef
2006
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002007def Test_screenattr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002008 CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2009 CheckDefFailure(['screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002010enddef
2011
2012def Test_screenchar()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002013 CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2014 CheckDefFailure(['screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002015enddef
2016
2017def Test_screenchars()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002018 CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2019 CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002020enddef
2021
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002022def Test_screenpos()
2023 CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2024 CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string')
2025 CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string')
2026 assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1))
2027enddef
2028
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002029def Test_screenstring()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002030 CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2031 CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002032enddef
2033
Bram Moolenaar94738d82020-10-21 14:25:07 +02002034def Test_search()
2035 new
2036 setline(1, ['foo', 'bar'])
2037 var val = 0
2038 # skip expr returns boolean
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002039 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002040 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002041 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002042 # skip expr returns number, only 0 and 1 are accepted
2043 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002044 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002045 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002046 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
2047 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
2048 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002049
2050 setline(1, "find this word")
2051 normal gg
2052 var col = 7
2053 assert_equal(1, search('this', '', 0, 0, 'col(".") > col'))
2054 normal 0
2055 assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col'))
2056
2057 col = 5
2058 normal 0
2059 assert_equal(0, search('this', '', 0, 0, 'col(".") > col'))
2060 normal 0
2061 assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col'))
2062 bwipe!
Bram Moolenaar94738d82020-10-21 14:25:07 +02002063enddef
2064
2065def Test_searchcount()
2066 new
2067 setline(1, "foo bar")
2068 :/foo
Bram Moolenaare0de1712020-12-02 17:36:54 +01002069 searchcount({recompute: true})
2070 ->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02002071 exact_match: 1,
2072 current: 1,
2073 total: 1,
2074 maxcount: 99,
2075 incomplete: 0})
2076 bwipe!
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002077 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 +02002078enddef
2079
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002080def Test_searchpair()
2081 new
2082 setline(1, "here { and } there")
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002083
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002084 normal f{
2085 var col = 15
2086 assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col'))
2087 assert_equal(12, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002088 normal 0f{
2089 assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col'))
2090
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002091 col = 8
2092 normal 0f{
2093 assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col'))
2094 assert_equal(6, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002095 normal 0f{
2096 assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col'))
2097
Bram Moolenaarff652882021-05-16 15:24:49 +02002098 var lines =<< trim END
2099 vim9script
2100 setline(1, '()')
2101 normal gg
2102 def Fail()
2103 try
2104 searchpairpos('(', '', ')', 'nW', '[0]->map("")')
2105 catch
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002106 g:caught = 'yes'
Bram Moolenaarff652882021-05-16 15:24:49 +02002107 endtry
2108 enddef
2109 Fail()
2110 END
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002111 CheckScriptSuccess(lines)
2112 assert_equal('yes', g:caught)
Bram Moolenaarff652882021-05-16 15:24:49 +02002113
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002114 unlet g:caught
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002115 bwipe!
2116enddef
2117
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002118def Test_server2client()
2119 CheckFeature clientserver
2120 CheckEnv DISPLAY
2121 CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2122 CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2123enddef
2124
Bram Moolenaar34453202021-01-31 13:08:38 +01002125def Test_set_get_bufline()
2126 # similar to Test_setbufline_getbufline()
2127 var lines =<< trim END
2128 new
2129 var b = bufnr('%')
2130 hide
2131 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
2132 assert_equal(['foo'], getbufline(b, 1))
2133 assert_equal(['bar'], getbufline(b, '$'))
2134 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
2135 exe "bd!" b
2136 assert_equal([], getbufline(b, 1, 2))
2137
2138 split Xtest
2139 setline(1, ['a', 'b', 'c'])
2140 b = bufnr('%')
2141 wincmd w
2142
2143 assert_equal(1, setbufline(b, 5, 'x'))
2144 assert_equal(1, setbufline(b, 5, ['x']))
2145 assert_equal(1, setbufline(b, 5, []))
2146 assert_equal(1, setbufline(b, 5, test_null_list()))
2147
2148 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
2149 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
2150 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
2151 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
2152
2153 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
2154
2155 assert_equal(0, setbufline(b, 4, ['d', 'e']))
2156 assert_equal(['c'], b->getbufline(3))
2157 assert_equal(['d'], getbufline(b, 4))
2158 assert_equal(['e'], getbufline(b, 5))
2159 assert_equal([], getbufline(b, 6))
2160 assert_equal([], getbufline(b, 2, 1))
2161
Bram Moolenaar00385112021-02-07 14:31:06 +01002162 if has('job')
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002163 setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())])
Bram Moolenaar00385112021-02-07 14:31:06 +01002164 assert_equal(["function('eval')",
2165 "{'key': 123}",
2166 "no process"],
2167 getbufline(b, 2, 4))
2168 endif
Bram Moolenaar34453202021-01-31 13:08:38 +01002169
2170 exe 'bwipe! ' .. b
2171 END
2172 CheckDefAndScriptSuccess(lines)
2173enddef
2174
Bram Moolenaar94738d82020-10-21 14:25:07 +02002175def Test_searchdecl()
2176 searchdecl('blah', true, true)->assert_equal(1)
2177enddef
2178
2179def Test_setbufvar()
2180 setbufvar(bufnr('%'), '&syntax', 'vim')
2181 &syntax->assert_equal('vim')
2182 setbufvar(bufnr('%'), '&ts', 16)
2183 &ts->assert_equal(16)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002184 setbufvar(bufnr('%'), '&ai', true)
2185 &ai->assert_equal(true)
2186 setbufvar(bufnr('%'), '&ft', 'filetype')
2187 &ft->assert_equal('filetype')
2188
Bram Moolenaar94738d82020-10-21 14:25:07 +02002189 settabwinvar(1, 1, '&syntax', 'vam')
2190 &syntax->assert_equal('vam')
2191 settabwinvar(1, 1, '&ts', 15)
2192 &ts->assert_equal(15)
2193 setlocal ts=8
Bram Moolenaarb0d81822021-01-03 15:55:10 +01002194 settabwinvar(1, 1, '&list', false)
2195 &list->assert_equal(false)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002196 settabwinvar(1, 1, '&list', true)
2197 &list->assert_equal(true)
2198 setlocal list&
Bram Moolenaar94738d82020-10-21 14:25:07 +02002199
2200 setbufvar('%', 'myvar', 123)
2201 getbufvar('%', 'myvar')->assert_equal(123)
2202enddef
2203
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002204def Test_setcharsearch()
2205 CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
2206 CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2207 var d: dict<any> = {char: 'x', forward: 1, until: 1}
2208 setcharsearch(d)
2209 assert_equal(d, getcharsearch())
2210enddef
2211
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002212def Test_setcmdpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002213 CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002214enddef
2215
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002216def Test_setfperm()
2217 CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2218 CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
2219enddef
2220
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002221def Test_setbufline()
2222 new
2223 var bnum = bufnr('%')
2224 :wincmd w
2225 setbufline(bnum, 1, range(1, 3))
2226 setbufline(bnum, 4, 'one')
2227 setbufline(bnum, 5, 10)
2228 setbufline(bnum, 6, ['two', 11])
2229 assert_equal(['1', '2', '3', 'one', '10', 'two', '11'], getbufline(bnum, 1, '$'))
2230 CheckDefFailure(['setbufline([1], 1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>')
2231 CheckDefFailure(['setbufline(1, [1], "x")'], 'E1013: Argument 2: type mismatch, expected string but got list<number>')
2232 CheckDefFailure(['setbufline(1, 1, {"a": 10})'], 'E1013: Argument 3: type mismatch, expected string but got dict<number>')
2233 bnum->bufwinid()->win_gotoid()
2234 bw!
2235enddef
2236
2237def Test_setcellwidths()
2238 CheckDefAndScriptFailure2(['setcellwidths(1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E714: List required')
2239 CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2240enddef
2241
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002242def Test_setline()
2243 new
2244 setline(1, range(1, 4))
2245 assert_equal(['1', '2', '3', '4'], getline(1, '$'))
2246 setline(1, ['a', 'b', 'c', 'd'])
2247 assert_equal(['a', 'b', 'c', 'd'], getline(1, '$'))
2248 setline(1, 'one')
2249 assert_equal(['one', 'b', 'c', 'd'], getline(1, '$'))
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002250 setline(1, 10)
2251 assert_equal(['10', 'b', 'c', 'd'], getline(1, '$'))
2252 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 +02002253 bw!
2254enddef
2255
Bram Moolenaar94738d82020-10-21 14:25:07 +02002256def Test_setloclist()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002257 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
2258 var what = {items: items}
Bram Moolenaar94738d82020-10-21 14:25:07 +02002259 setqflist([], ' ', what)
2260 setloclist(0, [], ' ', what)
2261enddef
2262
2263def Test_setreg()
2264 setreg('a', ['aaa', 'bbb', 'ccc'])
2265 var reginfo = getreginfo('a')
2266 setreg('a', reginfo)
2267 getreginfo('a')->assert_equal(reginfo)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01002268 assert_fails('setreg("ab", 0)', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002269enddef
2270
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002271def Test_sha256()
2272 CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2273 CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
2274 assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc'))
2275enddef
2276
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002277def Test_shiftwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002278 CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2279enddef
2280
2281def Test_sign_define()
2282 CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2283 CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2284 CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
2285enddef
2286
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002287def Test_sign_getdefined()
2288 CheckDefAndScriptFailure2(['sign_getdefined(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
2289 CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2290enddef
2291
2292def Test_sign_placelist()
2293 CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2294 CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2295enddef
2296
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002297def Test_sign_undefine()
2298 CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2299 CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:')
2300enddef
2301
2302def Test_sign_unplace()
2303 CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2304 CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2305 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 +02002306enddef
2307
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002308def Test_sign_unplacelist()
2309 CheckDefAndScriptFailure2(['sign_unplacelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2310 CheckDefAndScriptFailure2(['sign_unplacelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2311enddef
2312
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002313def Test_simplify()
2314 CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2315 call assert_equal('NonExistingFile', simplify('NonExistingFile'))
2316enddef
2317
Bram Moolenaar6601b622021-01-13 21:47:15 +01002318def Test_slice()
2319 assert_equal('12345', slice('012345', 1))
2320 assert_equal('123', slice('012345', 1, 4))
2321 assert_equal('1234', slice('012345', 1, -1))
2322 assert_equal('1', slice('012345', 1, -4))
2323 assert_equal('', slice('012345', 1, -5))
2324 assert_equal('', slice('012345', 1, -6))
2325
2326 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
2327 assert_equal([1, 2, 3], slice(range(6), 1, 4))
2328 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
2329 assert_equal([1], slice(range(6), 1, -4))
2330 assert_equal([], slice(range(6), 1, -5))
2331 assert_equal([], slice(range(6), 1, -6))
2332
2333 assert_equal(0z1122334455, slice(0z001122334455, 1))
2334 assert_equal(0z112233, slice(0z001122334455, 1, 4))
2335 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
2336 assert_equal(0z11, slice(0z001122334455, 1, -4))
2337 assert_equal(0z, slice(0z001122334455, 1, -5))
2338 assert_equal(0z, slice(0z001122334455, 1, -6))
2339enddef
2340
Bram Moolenaar94738d82020-10-21 14:25:07 +02002341def Test_spellsuggest()
2342 if !has('spell')
2343 MissingFeature 'spell'
2344 else
2345 spellsuggest('marrch', 1, true)->assert_equal(['March'])
2346 endif
2347enddef
2348
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002349def Test_sound_stop()
2350 CheckFeature sound
2351 CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2352enddef
2353
2354def Test_soundfold()
2355 CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2356 assert_equal('abc', soundfold('abc'))
2357enddef
2358
Bram Moolenaar94738d82020-10-21 14:25:07 +02002359def Test_sort_return_type()
2360 var res: list<number>
2361 res = [1, 2, 3]->sort()
2362enddef
2363
2364def Test_sort_argument()
Bram Moolenaar08cf0c02020-12-05 21:47:06 +01002365 var lines =<< trim END
2366 var res = ['b', 'a', 'c']->sort('i')
2367 res->assert_equal(['a', 'b', 'c'])
2368
2369 def Compare(a: number, b: number): number
2370 return a - b
2371 enddef
2372 var l = [3, 6, 7, 1, 8, 2, 4, 5]
2373 sort(l, Compare)
2374 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
2375 END
2376 CheckDefAndScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002377enddef
2378
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002379def Test_spellbadword()
2380 CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2381 spellbadword('good')->assert_equal(['', ''])
2382enddef
2383
Bram Moolenaar94738d82020-10-21 14:25:07 +02002384def Test_split()
2385 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
2386enddef
2387
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002388def Test_srand()
2389 CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2390 type(srand(100))->assert_equal(v:t_list)
2391enddef
2392
2393def Test_state()
2394 CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2395 assert_equal('', state('a'))
2396enddef
2397
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002398def Run_str2float()
2399 if !has('float')
2400 MissingFeature 'float'
2401 endif
2402 str2float("1.00")->assert_equal(1.00)
2403 str2float("2e-2")->assert_equal(0.02)
2404
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002405 CheckDefFailure(['str2float(123)'], 'E1013:')
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002406 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
2407 endif
2408enddef
2409
Bram Moolenaar94738d82020-10-21 14:25:07 +02002410def Test_str2nr()
2411 str2nr("1'000'000", 10, true)->assert_equal(1000000)
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002412
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002413 CheckDefFailure(['str2nr(123)'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002414 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002415 CheckDefFailure(['str2nr("123", "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002416 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002417 CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002418 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002419enddef
2420
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002421def Test_strcharlen()
2422 CheckDefAndScriptFailure2(['strcharlen([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2423 "abc"->strcharlen()->assert_equal(3)
2424 strcharlen(99)->assert_equal(2)
2425enddef
2426
Bram Moolenaar94738d82020-10-21 14:25:07 +02002427def Test_strchars()
2428 strchars("A\u20dd", true)->assert_equal(1)
2429enddef
2430
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002431def Test_strdisplaywidth()
2432 CheckDefAndScriptFailure2(['strdisplaywidth(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2433 CheckDefAndScriptFailure2(['strdisplaywidth("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2434enddef
2435
2436def Test_strftime()
2437 CheckDefAndScriptFailure2(['strftime(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2438 CheckDefAndScriptFailure2(['strftime("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2439enddef
2440
2441def Test_strgetchar()
2442 CheckDefAndScriptFailure2(['strgetchar(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2443 CheckDefAndScriptFailure2(['strgetchar("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2444enddef
2445
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002446def Test_stridx()
2447 CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2448 CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2449 CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2450enddef
2451
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002452def Test_strlen()
2453 CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2454 "abc"->strlen()->assert_equal(3)
2455 strlen(99)->assert_equal(2)
2456enddef
2457
2458def Test_strptime()
2459 CheckFunction strptime
2460 CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2461 CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number')
2462 # BUG: Directly calling strptime() in this function gives an "E117: Unknown
2463 # function" error on MS-Windows even with the above CheckFunction call for
2464 # strptime().
2465 #assert_true(strptime('%Y', '2021') != 0)
2466enddef
2467
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002468def Test_strridx()
2469 CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2470 CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2471 CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2472enddef
2473
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002474def Test_strtrans()
2475 CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2476 assert_equal('abc', strtrans('abc'))
2477enddef
2478
2479def Test_strwidth()
2480 CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2481 CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:')
2482 assert_equal(4, strwidth('abcd'))
2483enddef
2484
Bram Moolenaar94738d82020-10-21 14:25:07 +02002485def Test_submatch()
2486 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
Bram Moolenaar75ab91f2021-01-10 22:42:50 +01002487 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
Bram Moolenaar94738d82020-10-21 14:25:07 +02002488 var actual = substitute('A123456789', pat, Rep, '')
2489 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
2490 actual->assert_equal(expected)
2491enddef
2492
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002493def Test_substitute()
2494 var res = substitute('A1234', '\d', 'X', '')
2495 assert_equal('AX234', res)
2496
2497 if has('job')
2498 assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job')
2499 assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel')
2500 endif
2501enddef
2502
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002503def Test_swapinfo()
2504 CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2505 call assert_equal({error: 'Cannot open file'}, swapinfo('x'))
2506enddef
2507
2508def Test_swapname()
2509 CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2510 assert_fails('swapname("NonExistingBuf")', 'E94:')
2511enddef
2512
Bram Moolenaar94738d82020-10-21 14:25:07 +02002513def Test_synID()
2514 new
2515 setline(1, "text")
2516 synID(1, 1, true)->assert_equal(0)
2517 bwipe!
2518enddef
2519
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002520def Test_synIDtrans()
2521 CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2522enddef
2523
2524def Test_tabpagebuflist()
2525 CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2526 assert_equal([bufnr('')], tabpagebuflist())
2527 assert_equal([bufnr('')], tabpagebuflist(1))
2528enddef
2529
2530def Test_tabpagenr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002531 CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002532 assert_equal(1, tabpagenr('$'))
2533 assert_equal(1, tabpagenr())
2534enddef
2535
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002536def Test_tabpagewinnr()
2537 CheckDefAndScriptFailure2(['tabpagewinnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2538 CheckDefAndScriptFailure2(['tabpagewinnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2539enddef
2540
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002541def Test_taglist()
2542 CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2543 CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2544enddef
2545
2546def Test_term_dumpload()
2547 CheckRunVimInTerminal
2548 CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2549 CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2550 CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2')
2551enddef
2552
2553def Test_term_getaltscreen()
2554 CheckRunVimInTerminal
2555 CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
2556enddef
2557
2558def Test_term_getansicolors()
2559 CheckRunVimInTerminal
Dominique Pelleee410522021-07-12 22:15:24 +02002560 CheckFeature termguicolors
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002561 CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number')
2562enddef
2563
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002564def Test_term_getattr()
2565 CheckRunVimInTerminal
2566 CheckDefAndScriptFailure2(['term_getattr("x", "a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2567 CheckDefAndScriptFailure2(['term_getattr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2568enddef
2569
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002570def Test_term_getcursor()
2571 CheckRunVimInTerminal
2572 CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number')
2573enddef
2574
2575def Test_term_getjob()
2576 CheckRunVimInTerminal
2577 CheckDefAndScriptFailure2(['term_getjob(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E974: Using a Blob as a Number')
2578enddef
2579
2580def Test_term_getscrolled()
2581 CheckRunVimInTerminal
2582 CheckDefAndScriptFailure2(['term_getscrolled(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2583enddef
2584
2585def Test_term_getsize()
2586 CheckRunVimInTerminal
2587 CheckDefAndScriptFailure2(['term_getsize(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2588enddef
2589
2590def Test_term_getstatus()
2591 CheckRunVimInTerminal
2592 CheckDefAndScriptFailure2(['term_getstatus(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2593enddef
2594
2595def Test_term_gettitle()
2596 CheckRunVimInTerminal
2597 CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2598enddef
2599
Bram Moolenaar94738d82020-10-21 14:25:07 +02002600def Test_term_gettty()
2601 if !has('terminal')
2602 MissingFeature 'terminal'
2603 else
2604 var buf = Run_shell_in_terminal({})
2605 term_gettty(buf, true)->assert_notequal('')
2606 StopShellInTerminal(buf)
2607 endif
2608enddef
2609
2610def Test_term_start()
2611 if !has('terminal')
2612 MissingFeature 'terminal'
2613 else
2614 botright new
2615 var winnr = winnr()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002616 term_start(&shell, {curwin: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002617 winnr()->assert_equal(winnr)
2618 bwipe!
2619 endif
2620enddef
2621
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002622def Test_test_alloc_fail()
2623 CheckDefAndScriptFailure2(['test_alloc_fail("a", 10, 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2624 CheckDefAndScriptFailure2(['test_alloc_fail(10, "b", 20)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2625 CheckDefAndScriptFailure2(['test_alloc_fail(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E474: Invalid argument')
2626enddef
2627
2628def Test_test_feedinput()
2629 CheckDefAndScriptFailure2(['test_feedinput(test_void())'], 'E1013: Argument 1: type mismatch, expected string but got void', 'E1031: Cannot use void value')
2630 CheckDefAndScriptFailure2(['test_feedinput(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2631enddef
2632
2633def Test_test_getvalue()
2634 CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument')
2635enddef
2636
2637def Test_test_ignore_error()
2638 CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2639 test_ignore_error('RESET')
2640enddef
2641
2642def Test_test_option_not_set()
2643 CheckDefAndScriptFailure2(['test_option_not_set([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2644enddef
2645
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002646def Test_test_override()
2647 CheckDefAndScriptFailure2(['test_override(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2648 CheckDefAndScriptFailure2(['test_override("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2649enddef
2650
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002651def Test_test_setmouse()
2652 CheckDefAndScriptFailure2(['test_setmouse("a", 10)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2653 CheckDefAndScriptFailure2(['test_setmouse(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2654enddef
2655
2656def Test_test_settime()
2657 CheckDefAndScriptFailure2(['test_settime([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2658enddef
2659
2660def Test_test_srand_seed()
2661 CheckDefAndScriptFailure2(['test_srand_seed([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2662 CheckDefAndScriptFailure2(['test_srand_seed("10")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2663enddef
2664
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002665def Test_timer_info()
2666 CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2667 assert_equal([], timer_info(100))
2668 assert_equal([], timer_info())
2669enddef
2670
Bram Moolenaar94738d82020-10-21 14:25:07 +02002671def Test_timer_paused()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002672 var id = timer_start(50, () => 0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002673 timer_pause(id, true)
2674 var info = timer_info(id)
2675 info[0]['paused']->assert_equal(1)
2676 timer_stop(id)
2677enddef
2678
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002679def Test_timer_stop()
2680 CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2681 assert_equal(0, timer_stop(100))
2682enddef
2683
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002684def Test_tolower()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002685 CheckDefFailure(['tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002686enddef
2687
2688def Test_toupper()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002689 CheckDefFailure(['toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002690enddef
2691
2692def Test_tr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002693 CheckDefFailure(['tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2694 CheckDefFailure(['tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
2695 CheckDefFailure(['tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
2696enddef
2697
2698def Test_trim()
2699 CheckDefAndScriptFailure2(['trim(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2700 CheckDefAndScriptFailure2(['trim("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2701 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 +02002702enddef
2703
Bram Moolenaar9da32e42021-07-09 19:53:57 +02002704def Test_typename()
2705 if has('float')
2706 assert_equal('func([unknown], [unknown]): float', typename(function('pow')))
2707 endif
2708enddef
2709
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002710def Test_undofile()
2711 CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2712 assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t'))
2713enddef
2714
2715def Test_values()
2716 CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2717 assert_equal([], {}->values())
2718 assert_equal(['sun'], {star: 'sun'}->values())
2719enddef
2720
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002721def Test_virtcol()
2722 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 +02002723 new
2724 setline(1, ['abcdefgh'])
2725 cursor(1, 4)
2726 assert_equal(4, virtcol('.'))
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02002727 assert_equal(4, virtcol([1, 4]))
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002728 assert_equal(9, virtcol([1, '$']))
2729 assert_equal(0, virtcol([10, '$']))
2730 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002731enddef
2732
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002733def Test_visualmode()
2734 CheckDefFailure(['visualmode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
2735 CheckDefFailure(['visualmode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
2736enddef
2737
Bram Moolenaar37487e12021-01-12 22:08:53 +01002738def Test_win_execute()
2739 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
Bram Moolenaar52312242021-07-11 18:23:19 +02002740 assert_equal("\n" .. winnr(), 'echo winnr()'->win_execute(win_getid()))
2741 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()', 'silent'))
Bram Moolenaar37487e12021-01-12 22:08:53 +01002742 assert_equal('', win_execute(342343, 'echo winnr()'))
2743enddef
2744
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002745def Test_win_findbuf()
2746 CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2747 assert_equal([], win_findbuf(1000))
2748 assert_equal([win_getid()], win_findbuf(bufnr('')))
2749enddef
2750
2751def Test_win_getid()
2752 CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2753 CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string')
2754 assert_equal(win_getid(), win_getid(1, 1))
2755enddef
2756
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002757def Test_win_gettype()
2758 CheckDefAndScriptFailure2(['win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2759enddef
2760
2761def Test_win_gotoid()
2762 CheckDefAndScriptFailure2(['win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2763enddef
2764
2765def Test_win_id2tabwin()
2766 CheckDefAndScriptFailure2(['win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2767enddef
2768
2769def Test_win_id2win()
2770 CheckDefAndScriptFailure2(['win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2771enddef
2772
2773def Test_win_screenpos()
2774 CheckDefAndScriptFailure2(['win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2775enddef
2776
Bram Moolenaar94738d82020-10-21 14:25:07 +02002777def Test_win_splitmove()
2778 split
Bram Moolenaare0de1712020-12-02 17:36:54 +01002779 win_splitmove(1, 2, {vertical: true, rightbelow: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002780 close
2781enddef
2782
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002783def Test_winbufnr()
2784 CheckDefAndScriptFailure2(['winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2785enddef
2786
2787def Test_winheight()
2788 CheckDefAndScriptFailure2(['winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2789enddef
2790
2791def Test_winlayout()
2792 CheckDefAndScriptFailure2(['winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2793enddef
2794
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002795def Test_winnr()
2796 CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2797 assert_equal(1, winnr())
2798 assert_equal(1, winnr('$'))
2799enddef
2800
Bram Moolenaar285b15f2020-12-29 20:25:19 +01002801def Test_winrestcmd()
2802 split
2803 var cmd = winrestcmd()
2804 wincmd _
2805 exe cmd
2806 assert_equal(cmd, winrestcmd())
2807 close
2808enddef
2809
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002810def Test_winrestview()
2811 CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2812 :%d _
2813 setline(1, 'Hello World')
2814 winrestview({lnum: 1, col: 6})
2815 assert_equal([1, 7], [line('.'), col('.')])
2816enddef
2817
Bram Moolenaar43b69b32021-01-07 20:23:33 +01002818def Test_winsaveview()
2819 var view: dict<number> = winsaveview()
2820
2821 var lines =<< trim END
2822 var view: list<number> = winsaveview()
2823 END
2824 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
2825enddef
2826
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002827def Test_winwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002828 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 +02002829enddef
2830
2831def Test_xor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002832 CheckDefAndScriptFailure2(['xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2833 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 +02002834enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02002835
2836" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker