blob: c40780f4aede3a575676b7680e9107f1f60bba8e [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
78def Test_add_list()
79 var l: list<number> # defaults to empty list
80 add(l, 9)
81 assert_equal([9], l)
82
83 var lines =<< trim END
84 var l: list<number>
85 add(l, "x")
86 END
87 CheckDefFailure(lines, 'E1012:', 2)
88
89 lines =<< trim END
Bram Moolenaarb7c21af2021-04-18 14:12:31 +020090 add(test_null_list(), 123)
91 END
92 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
93
94 lines =<< trim END
Bram Moolenaar94738d82020-10-21 14:25:07 +020095 var l: list<number> = test_null_list()
96 add(l, 123)
97 END
98 CheckDefExecFailure(lines, 'E1130:', 2)
Bram Moolenaarb7c21af2021-04-18 14:12:31 +020099
100 # Getting variable with NULL list allocates a new list at script level
101 lines =<< trim END
102 vim9script
103 var l: list<number> = test_null_list()
104 add(l, 123)
105 END
106 CheckScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200107enddef
108
109def Test_add_blob()
110 var b1: blob = 0z12
111 add(b1, 0x34)
112 assert_equal(0z1234, b1)
113
114 var b2: blob # defaults to empty blob
115 add(b2, 0x67)
116 assert_equal(0z67, b2)
117
118 var lines =<< trim END
119 var b: blob
120 add(b, "x")
121 END
122 CheckDefFailure(lines, 'E1012:', 2)
123
124 lines =<< trim END
Bram Moolenaarb7c21af2021-04-18 14:12:31 +0200125 add(test_null_blob(), 123)
126 END
127 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
128
129 lines =<< trim END
Bram Moolenaar94738d82020-10-21 14:25:07 +0200130 var b: blob = test_null_blob()
131 add(b, 123)
132 END
133 CheckDefExecFailure(lines, 'E1131:', 2)
Bram Moolenaarb7c21af2021-04-18 14:12:31 +0200134
135 # Getting variable with NULL blob allocates a new blob at script level
136 lines =<< trim END
137 vim9script
138 var b: blob = test_null_blob()
139 add(b, 123)
140 END
141 CheckScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200142enddef
143
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200144def Test_and()
145 CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
146 CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
147enddef
148
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100149def Test_append()
150 new
151 setline(1, range(3))
152 var res1: number = append(1, 'one')
153 assert_equal(0, res1)
154 var res2: bool = append(3, 'two')
155 assert_equal(false, res2)
156 assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6))
Bram Moolenaarb2ac7d02021-03-28 15:46:16 +0200157
158 append(0, 'zero')
159 assert_equal('zero', getline(1))
160 bwipe!
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100161enddef
162
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200163def Test_argc()
164 CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
165enddef
166
167def Test_arglistid()
168 CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
169 CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string')
170 CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
171enddef
172
173def Test_argv()
174 CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
175 CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
176 CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
177enddef
178
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100179def Test_balloon_show()
180 CheckGui
181 CheckFeature balloon_eval
182
183 assert_fails('balloon_show(true)', 'E1174:')
184enddef
185
186def Test_balloon_split()
Bram Moolenaar7b45d462021-03-27 19:09:02 +0100187 CheckFeature balloon_eval_term
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100188
189 assert_fails('balloon_split(true)', 'E1174:')
190enddef
191
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100192def Test_browse()
193 CheckFeature browse
194
195 var lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100196 browse(1, 2, 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100197 END
198 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
199 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100200 browse(1, 'title', 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100201 END
202 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
203 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100204 browse(1, 'title', 'dir', 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100205 END
206 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
207enddef
208
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100209def Test_bufexists()
210 assert_fails('bufexists(true)', 'E1174')
211enddef
212
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100213def Test_buflisted()
214 var res: bool = buflisted('asdf')
215 assert_equal(false, res)
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100216 assert_fails('buflisted(true)', 'E1174')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100217enddef
218
Bram Moolenaar94738d82020-10-21 14:25:07 +0200219def Test_bufname()
220 split SomeFile
221 bufname('%')->assert_equal('SomeFile')
222 edit OtherFile
223 bufname('#')->assert_equal('SomeFile')
224 close
225enddef
226
227def Test_bufnr()
228 var buf = bufnr()
229 bufnr('%')->assert_equal(buf)
230
231 buf = bufnr('Xdummy', true)
232 buf->assert_notequal(-1)
233 exe 'bwipe! ' .. buf
234enddef
235
236def Test_bufwinid()
237 var origwin = win_getid()
238 below split SomeFile
239 var SomeFileID = win_getid()
240 below split OtherFile
241 below split SomeFile
242 bufwinid('SomeFile')->assert_equal(SomeFileID)
243
244 win_gotoid(origwin)
245 only
246 bwipe SomeFile
247 bwipe OtherFile
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100248
249 assert_fails('bufwinid(true)', 'E1138')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200250enddef
251
252def Test_call_call()
253 var l = [3, 2, 1]
254 call('reverse', [l])
255 l->assert_equal([1, 2, 3])
256enddef
257
Bram Moolenaarc5809432021-03-27 21:23:30 +0100258def Test_ch_logfile()
Bram Moolenaar886e5e72021-04-05 13:36:34 +0200259 if !has('channel')
260 CheckFeature channel
261 endif
Bram Moolenaarc5809432021-03-27 21:23:30 +0100262 assert_fails('ch_logfile(true)', 'E1174')
263 assert_fails('ch_logfile("foo", true)', 'E1174')
264enddef
265
Bram Moolenaar94738d82020-10-21 14:25:07 +0200266def Test_char2nr()
267 char2nr('あ', true)->assert_equal(12354)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100268
269 assert_fails('char2nr(true)', 'E1174')
270enddef
271
272def Test_charclass()
273 assert_fails('charclass(true)', 'E1174')
274enddef
275
276def Test_chdir()
277 assert_fails('chdir(true)', 'E1174')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200278enddef
279
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200280def Test_clearmatches()
281 CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
282enddef
283
Bram Moolenaar94738d82020-10-21 14:25:07 +0200284def Test_col()
285 new
286 setline(1, 'asdf')
287 col([1, '$'])->assert_equal(5)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100288
289 assert_fails('col(true)', 'E1174')
290enddef
291
292def Test_confirm()
293 if !has('dialog_con') && !has('dialog_gui')
294 CheckFeature dialog_con
295 endif
296
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100297 assert_fails('confirm(true)', 'E1174')
298 assert_fails('confirm("yes", true)', 'E1174')
299 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200300enddef
301
302def Test_copy_return_type()
303 var l = copy([1, 2, 3])
304 var res = 0
305 for n in l
306 res += n
307 endfor
308 res->assert_equal(6)
309
310 var dl = deepcopy([1, 2, 3])
311 res = 0
312 for n in dl
313 res += n
314 endfor
315 res->assert_equal(6)
316
317 dl = deepcopy([1, 2, 3], true)
318enddef
319
320def Test_count()
321 count('ABC ABC ABC', 'b', true)->assert_equal(3)
322 count('ABC ABC ABC', 'b', false)->assert_equal(0)
323enddef
324
Bram Moolenaar9a963372020-12-21 21:58:46 +0100325def Test_cursor()
326 new
327 setline(1, range(4))
328 cursor(2, 1)
329 assert_equal(2, getcurpos()[1])
330 cursor('$', 1)
331 assert_equal(4, getcurpos()[1])
332
333 var lines =<< trim END
334 cursor('2', 1)
335 END
336 CheckDefExecAndScriptFailure(lines, 'E475:')
337enddef
338
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200339def Test_debugbreak()
340 CheckMSWindows
341 CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
342enddef
343
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100344def Test_delete()
345 var res: bool = delete('doesnotexist')
346 assert_equal(true, res)
347enddef
348
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100349def Test_executable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100350 assert_false(executable(""))
351 assert_false(executable(test_null_string()))
352
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100353 CheckDefExecFailure(['echo executable(123)'], 'E1174:')
354 CheckDefExecFailure(['echo executable(true)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100355enddef
356
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200357def Test_execute()
358 var res = execute("echo 'hello'")
359 assert_equal("\nhello", res)
360 res = execute(["echo 'here'", "echo 'there'"])
361 assert_equal("\nhere\nthere", res)
362
363 CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
364 CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
365 CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
366 CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
367enddef
368
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100369def Test_exepath()
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100370 CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
371 CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100372 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100373enddef
374
Bram Moolenaar94738d82020-10-21 14:25:07 +0200375def Test_expand()
376 split SomeFile
377 expand('%', true, true)->assert_equal(['SomeFile'])
378 close
379enddef
380
Bram Moolenaar02795102021-05-03 21:40:26 +0200381def Test_expandcmd()
382 $FOO = "blue"
383 assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
384
385 assert_equal("yes", expandcmd("`={a: 'yes'}['a']`"))
386enddef
387
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100388def Test_extend_arg_types()
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100389 g:number_one = 1
390 g:string_keep = 'keep'
391 var lines =<< trim END
392 assert_equal([1, 2, 3], extend([1, 2], [3]))
393 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
394 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
395 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100396
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100397 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
398 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
399 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
400 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100401
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100402 var res: list<dict<any>>
403 extend(res, mapnew([1, 2], (_, v) => ({})))
404 assert_equal([{}, {}], res)
405 END
406 CheckDefAndScriptSuccess(lines)
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100407
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200408 CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100409 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
410 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
411 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
412
Bram Moolenaare0de1712020-12-02 17:36:54 +0100413 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
414 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
415 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
Bram Moolenaar351ead02021-01-16 16:07:01 +0100416
417 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
Bram Moolenaare32e5162021-01-21 20:21:29 +0100418 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100419enddef
420
Bram Moolenaarb0e6b512021-01-12 20:23:40 +0100421def Test_extendnew()
422 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
423 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
424
425 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
426 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
427 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
428 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
429enddef
430
Bram Moolenaar94738d82020-10-21 14:25:07 +0200431def Test_extend_return_type()
432 var l = extend([1, 2], [3])
433 var res = 0
434 for n in l
435 res += n
436 endfor
437 res->assert_equal(6)
438enddef
439
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100440func g:ExtendDict(d)
441 call extend(a:d, #{xx: 'x'})
442endfunc
443
444def Test_extend_dict_item_type()
445 var lines =<< trim END
446 var d: dict<number> = {a: 1}
447 extend(d, {b: 2})
448 END
449 CheckDefAndScriptSuccess(lines)
450
451 lines =<< trim END
452 var d: dict<number> = {a: 1}
453 extend(d, {b: 'x'})
454 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100455 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100456
457 lines =<< trim END
458 var d: dict<number> = {a: 1}
459 g:ExtendDict(d)
460 END
461 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
462 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
463enddef
464
465func g:ExtendList(l)
466 call extend(a:l, ['x'])
467endfunc
468
469def Test_extend_list_item_type()
470 var lines =<< trim END
471 var l: list<number> = [1]
472 extend(l, [2])
473 END
474 CheckDefAndScriptSuccess(lines)
475
476 lines =<< trim END
477 var l: list<number> = [1]
478 extend(l, ['x'])
479 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100480 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100481
482 lines =<< trim END
483 var l: list<number> = [1]
484 g:ExtendList(l)
485 END
486 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
487 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
488enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200489
Bram Moolenaar93e1cae2021-03-13 21:24:56 +0100490def Test_extend_with_error_function()
491 var lines =<< trim END
492 vim9script
493 def F()
494 {
495 var m = 10
496 }
497 echo m
498 enddef
499
500 def Test()
501 var d: dict<any> = {}
502 d->extend({A: 10, Func: function('F', [])})
503 enddef
504
505 Test()
506 END
507 CheckScriptFailure(lines, 'E1001: Variable not found: m')
508enddef
509
Bram Moolenaar64ed4d42021-01-12 21:22:31 +0100510def Test_job_info_return_type()
511 if has('job')
512 job_start(&shell)
513 var jobs = job_info()
Bram Moolenaara47e05f2021-01-12 21:49:00 +0100514 assert_equal('list<job>', typename(jobs))
515 assert_equal('dict<any>', typename(job_info(jobs[0])))
Bram Moolenaar64ed4d42021-01-12 21:22:31 +0100516 job_stop(jobs[0])
517 endif
518enddef
519
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100520def Test_filereadable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100521 assert_false(filereadable(""))
522 assert_false(filereadable(test_null_string()))
523
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100524 CheckDefExecFailure(['echo filereadable(123)'], 'E1174:')
525 CheckDefExecFailure(['echo filereadable(true)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100526enddef
527
528def Test_filewritable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100529 assert_false(filewritable(""))
530 assert_false(filewritable(test_null_string()))
531
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100532 CheckDefExecFailure(['echo filewritable(123)'], 'E1174:')
533 CheckDefExecFailure(['echo filewritable(true)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100534enddef
535
536def Test_finddir()
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100537 CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
538 CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100539 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100540enddef
541
542def Test_findfile()
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100543 CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
544 CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100545 CheckDefExecFailure(['echo findfile("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100546enddef
547
Bram Moolenaar3b690062021-02-01 20:14:51 +0100548def Test_flattennew()
549 var lines =<< trim END
550 var l = [1, [2, [3, 4]], 5]
551 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
552 call assert_equal([1, [2, [3, 4]], 5], l)
553
554 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
555 call assert_equal([1, [2, [3, 4]], 5], l)
556 END
557 CheckDefAndScriptSuccess(lines)
558
559 lines =<< trim END
560 echo flatten([1, 2, 3])
561 END
562 CheckDefAndScriptFailure(lines, 'E1158:')
563enddef
564
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200565" Test for float functions argument type
566def Test_float_funcs_args()
567 CheckFeature float
568
569 # acos()
570 CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
571 # asin()
572 CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
573 # atan()
574 CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
575 # atan2()
576 CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
577 CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
578 CheckDefFailure(['echo atan2(1.2)'], 'E119:')
579 # ceil()
580 CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
581 # cos()
582 CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
583 # cosh()
584 CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
585 # exp()
586 CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
587 # float2nr()
588 CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
589 # floor()
590 CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
591 # fmod()
592 CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
593 CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
594 CheckDefFailure(['echo fmod(1.1)'], 'E119:')
595 # isinf()
596 CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
597 # isnan()
598 CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
599 # log()
600 CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
601 # log10()
602 CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
603 # pow()
604 CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
605 CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
606 CheckDefFailure(['echo pow(1.1)'], 'E119:')
607 # round()
608 CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
609 # sin()
610 CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
611 # sinh()
612 CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
613 # sqrt()
614 CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
615 # tan()
616 CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
617 # tanh()
618 CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
619 # trunc()
620 CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
621enddef
622
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100623def Test_fnamemodify()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100624 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
625 CheckDefSuccess(['echo fnamemodify("", ":p")'])
626 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
627 CheckDefSuccess(['echo fnamemodify("file", "")'])
628
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100629 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1174: String required for argument 1')
630 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1174: String required for argument 1')
631 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1174: String required for argument 2')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100632enddef
633
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100634def Wrong_dict_key_type(items: list<number>): list<number>
635 return filter(items, (_, val) => get({[val]: 1}, 'x'))
636enddef
637
Bram Moolenaar94738d82020-10-21 14:25:07 +0200638def Test_filter_wrong_dict_key_type()
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100639 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200640enddef
641
642def Test_filter_return_type()
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200643 var l = filter([1, 2, 3], (_, _) => 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200644 var res = 0
645 for n in l
646 res += n
647 endfor
648 res->assert_equal(6)
649enddef
650
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100651def Test_filter_missing_argument()
652 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200653 var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100654 res->assert_equal({aa: [1], ac: [3]})
655enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200656
Bram Moolenaar7d840e92021-05-26 21:10:11 +0200657def Test_fullcommand()
658 assert_equal('next', fullcommand('n'))
659 assert_equal('noremap', fullcommand('no'))
660 assert_equal('noremap', fullcommand('nor'))
661 assert_equal('normal', fullcommand('norm'))
662
663 assert_equal('', fullcommand('k'))
664 assert_equal('keepmarks', fullcommand('ke'))
665 assert_equal('keepmarks', fullcommand('kee'))
666 assert_equal('keepmarks', fullcommand('keep'))
667 assert_equal('keepjumps', fullcommand('keepj'))
668
669 assert_equal('dlist', fullcommand('dl'))
670 assert_equal('', fullcommand('dp'))
671 assert_equal('delete', fullcommand('del'))
672 assert_equal('', fullcommand('dell'))
673 assert_equal('', fullcommand('delp'))
674
675 assert_equal('srewind', fullcommand('sre'))
676 assert_equal('scriptnames', fullcommand('scr'))
677 assert_equal('', fullcommand('scg'))
678enddef
679
Bram Moolenaar94738d82020-10-21 14:25:07 +0200680def Test_garbagecollect()
681 garbagecollect(true)
682enddef
683
684def Test_getbufinfo()
685 var bufinfo = getbufinfo(bufnr())
686 getbufinfo('%')->assert_equal(bufinfo)
687
688 edit Xtestfile1
689 hide edit Xtestfile2
690 hide enew
Bram Moolenaare0de1712020-12-02 17:36:54 +0100691 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200692 ->len()->assert_equal(3)
693 bwipe Xtestfile1 Xtestfile2
694enddef
695
696def Test_getbufline()
697 e SomeFile
698 var buf = bufnr()
699 e #
700 var lines = ['aaa', 'bbb', 'ccc']
701 setbufline(buf, 1, lines)
702 getbufline('#', 1, '$')->assert_equal(lines)
Bram Moolenaare6e70a12020-10-22 18:23:38 +0200703 getbufline(-1, '$', '$')->assert_equal([])
704 getbufline(-1, 1, '$')->assert_equal([])
Bram Moolenaar94738d82020-10-21 14:25:07 +0200705
706 bwipe!
707enddef
708
709def Test_getchangelist()
710 new
711 setline(1, 'some text')
712 var changelist = bufnr()->getchangelist()
713 getchangelist('%')->assert_equal(changelist)
714 bwipe!
715enddef
716
717def Test_getchar()
718 while getchar(0)
719 endwhile
720 getchar(true)->assert_equal(0)
721enddef
722
Bram Moolenaar7ad67d12021-03-10 16:08:26 +0100723def Test_getenv()
724 if getenv('does-not_exist') == ''
725 assert_report('getenv() should return null')
726 endif
727 if getenv('does-not_exist') == null
728 else
729 assert_report('getenv() should return null')
730 endif
731 $SOMEENVVAR = 'some'
732 assert_equal('some', getenv('SOMEENVVAR'))
733 unlet $SOMEENVVAR
734enddef
735
Bram Moolenaar94738d82020-10-21 14:25:07 +0200736def Test_getcompletion()
737 set wildignore=*.vim,*~
738 var l = getcompletion('run', 'file', true)
739 l->assert_equal([])
740 set wildignore&
741enddef
742
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200743def Test_getcurpos()
744 CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
745enddef
746
747def Test_getcursorcharpos()
748 CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
749enddef
750
751def Test_getcwd()
752 CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
753 CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
754 CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
755enddef
756
Bram Moolenaar94738d82020-10-21 14:25:07 +0200757def Test_getloclist_return_type()
758 var l = getloclist(1)
759 l->assert_equal([])
760
Bram Moolenaare0de1712020-12-02 17:36:54 +0100761 var d = getloclist(1, {items: 0})
762 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200763enddef
764
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100765def Test_getfperm()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100766 assert_equal('', getfperm(""))
767 assert_equal('', getfperm(test_null_string()))
768
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100769 CheckDefExecFailure(['echo getfperm(true)'], 'E1174:')
770 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100771enddef
772
773def Test_getfsize()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100774 assert_equal(-1, getfsize(""))
775 assert_equal(-1, getfsize(test_null_string()))
776
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100777 CheckDefExecFailure(['echo getfsize(true)'], 'E1174:')
778 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100779enddef
780
781def Test_getftime()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100782 assert_equal(-1, getftime(""))
783 assert_equal(-1, getftime(test_null_string()))
784
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100785 CheckDefExecFailure(['echo getftime(true)'], 'E1174:')
786 CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100787enddef
788
789def Test_getftype()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100790 assert_equal('', getftype(""))
791 assert_equal('', getftype(test_null_string()))
792
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100793 CheckDefExecFailure(['echo getftype(true)'], 'E1174:')
794 CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100795enddef
796
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200797def Test_getjumplist()
798 CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
799 CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
800 CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
801enddef
802
803def Test_getmatches()
804 CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
805enddef
806
Bram Moolenaar94738d82020-10-21 14:25:07 +0200807def Test_getqflist_return_type()
808 var l = getqflist()
809 l->assert_equal([])
810
Bram Moolenaare0de1712020-12-02 17:36:54 +0100811 var d = getqflist({items: 0})
812 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200813enddef
814
815def Test_getreg()
816 var lines = ['aaa', 'bbb', 'ccc']
817 setreg('a', lines)
818 getreg('a', true, true)->assert_equal(lines)
Bram Moolenaar418a29f2021-02-10 22:23:41 +0100819 assert_fails('getreg("ab")', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200820enddef
821
822def Test_getreg_return_type()
823 var s1: string = getreg('"')
824 var s2: string = getreg('"', 1)
825 var s3: list<string> = getreg('"', 1, 1)
826enddef
827
Bram Moolenaar418a29f2021-02-10 22:23:41 +0100828def Test_getreginfo()
829 var text = 'abc'
830 setreg('a', text)
831 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
832 assert_fails('getreginfo("ab")', 'E1162:')
833enddef
834
835def Test_getregtype()
836 var lines = ['aaa', 'bbb', 'ccc']
837 setreg('a', lines)
838 getregtype('a')->assert_equal('V')
839 assert_fails('getregtype("ab")', 'E1162:')
840enddef
841
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200842def Test_gettabinfo()
843 CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
844enddef
845
846def Test_gettagstack()
847 CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
848enddef
849
850def Test_getwininfo()
851 CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
852enddef
853
854def Test_getwinpos()
855 CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
856enddef
857
Bram Moolenaar94738d82020-10-21 14:25:07 +0200858def Test_glob()
859 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
860enddef
861
862def Test_globpath()
863 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
864enddef
865
866def Test_has()
867 has('eval', true)->assert_equal(1)
868enddef
869
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200870def Test_haslocaldir()
871 CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
872 CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
873 CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
874enddef
875
Bram Moolenaar94738d82020-10-21 14:25:07 +0200876def Test_hasmapto()
877 hasmapto('foobar', 'i', true)->assert_equal(0)
878 iabbrev foo foobar
879 hasmapto('foobar', 'i', true)->assert_equal(1)
880 iunabbrev foo
881enddef
882
883def Test_index()
884 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
885enddef
886
Bram Moolenaar193f6202020-11-16 20:08:35 +0100887let s:number_one = 1
888let s:number_two = 2
889let s:string_keep = 'keep'
890
Bram Moolenaarca174532020-10-21 16:42:22 +0200891def Test_insert()
Bram Moolenaar94738d82020-10-21 14:25:07 +0200892 var l = insert([2, 1], 3)
893 var res = 0
894 for n in l
895 res += n
896 endfor
897 res->assert_equal(6)
Bram Moolenaarca174532020-10-21 16:42:22 +0200898
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200899 var m: any = []
900 insert(m, 4)
901 call assert_equal([4], m)
902 extend(m, [6], 0)
903 call assert_equal([6, 4], m)
904
Bram Moolenaar39211cb2021-04-18 15:48:04 +0200905 var lines =<< trim END
906 insert(test_null_list(), 123)
907 END
908 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
909
910 lines =<< trim END
911 insert(test_null_blob(), 123)
912 END
913 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
914
Bram Moolenaarca174532020-10-21 16:42:22 +0200915 assert_equal([1, 2, 3], insert([2, 3], 1))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100916 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
Bram Moolenaarca174532020-10-21 16:42:22 +0200917 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100918 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
Bram Moolenaarca174532020-10-21 16:42:22 +0200919 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
920 assert_equal(0z1234, insert(0z34, 0x12))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100921
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200922 CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
Bram Moolenaarca174532020-10-21 16:42:22 +0200923 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
924 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200925enddef
926
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200927def Test_invert()
928 CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
929enddef
930
Bram Moolenaar94738d82020-10-21 14:25:07 +0200931def Test_keys_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100932 const var: list<string> = {a: 1, b: 2}->keys()
Bram Moolenaar94738d82020-10-21 14:25:07 +0200933 var->assert_equal(['a', 'b'])
934enddef
935
Bram Moolenaarc5809432021-03-27 21:23:30 +0100936def Test_line()
937 assert_fails('line(true)', 'E1174')
938enddef
939
Bram Moolenaar94738d82020-10-21 14:25:07 +0200940def Test_list2str_str2list_utf8()
941 var s = "\u3042\u3044"
942 var l = [0x3042, 0x3044]
943 str2list(s, true)->assert_equal(l)
944 list2str(l, true)->assert_equal(s)
945enddef
946
947def SID(): number
948 return expand('<SID>')
949 ->matchstr('<SNR>\zs\d\+\ze_$')
950 ->str2nr()
951enddef
952
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200953def Test_listener_remove()
954 CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
955enddef
956
Bram Moolenaar70250fb2021-01-16 19:01:53 +0100957def Test_map_function_arg()
958 var lines =<< trim END
959 def MapOne(i: number, v: string): string
960 return i .. ':' .. v
961 enddef
962 var l = ['a', 'b', 'c']
963 map(l, MapOne)
964 assert_equal(['0:a', '1:b', '2:c'], l)
965 END
966 CheckDefAndScriptSuccess(lines)
Bram Moolenaar8da6d6d2021-06-05 18:15:09 +0200967
968 lines =<< trim END
969 range(3)->map((a, b, c) => a + b + c)
970 END
971 CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
972 lines =<< trim END
973 range(3)->map((a, b, c, d) => a + b + c + d)
974 END
975 CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
Bram Moolenaar70250fb2021-01-16 19:01:53 +0100976enddef
977
978def Test_map_item_type()
979 var lines =<< trim END
980 var l = ['a', 'b', 'c']
981 map(l, (k, v) => k .. '/' .. v )
982 assert_equal(['0/a', '1/b', '2/c'], l)
983 END
984 CheckDefAndScriptSuccess(lines)
985
986 lines =<< trim END
987 var l: list<number> = [0]
988 echo map(l, (_, v) => [])
989 END
990 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
991
992 lines =<< trim END
993 var l: list<number> = range(2)
994 echo map(l, (_, v) => [])
995 END
996 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
997
998 lines =<< trim END
999 var d: dict<number> = {key: 0}
1000 echo map(d, (_, v) => [])
1001 END
1002 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1003enddef
1004
Bram Moolenaar94738d82020-10-21 14:25:07 +02001005def Test_maparg()
1006 var lnum = str2nr(expand('<sflnum>'))
1007 map foo bar
Bram Moolenaare0de1712020-12-02 17:36:54 +01001008 maparg('foo', '', false, true)->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001009 lnum: lnum + 1,
1010 script: 0,
1011 mode: ' ',
1012 silent: 0,
1013 noremap: 0,
1014 lhs: 'foo',
1015 lhsraw: 'foo',
1016 nowait: 0,
1017 expr: 0,
1018 sid: SID(),
1019 rhs: 'bar',
1020 buffer: 0})
1021 unmap foo
1022enddef
1023
1024def Test_mapcheck()
1025 iabbrev foo foobar
1026 mapcheck('foo', 'i', true)->assert_equal('foobar')
1027 iunabbrev foo
1028enddef
1029
1030def Test_maparg_mapset()
1031 nnoremap <F3> :echo "hit F3"<CR>
1032 var mapsave = maparg('<F3>', 'n', false, true)
1033 mapset('n', false, mapsave)
1034
1035 nunmap <F3>
1036enddef
1037
Bram Moolenaar027c4ab2021-02-21 16:20:18 +01001038def Test_map_failure()
1039 CheckFeature job
1040
1041 var lines =<< trim END
1042 vim9script
1043 writefile([], 'Xtmpfile')
1044 silent e Xtmpfile
1045 var d = {[bufnr('%')]: {a: 0}}
1046 au BufReadPost * Func()
1047 def Func()
1048 if d->has_key('')
1049 endif
1050 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
1051 enddef
1052 e
1053 END
1054 CheckScriptFailure(lines, 'E1013:')
1055 au! BufReadPost
1056 delete('Xtmpfile')
1057enddef
1058
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001059def Test_matcharg()
1060 CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1061enddef
1062
1063def Test_matchdelete()
1064 CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1065 CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1066 CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1067enddef
1068
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001069def Test_max()
1070 g:flag = true
1071 var l1: list<number> = g:flag
1072 ? [1, max([2, 3])]
1073 : [4, 5]
1074 assert_equal([1, 3], l1)
1075
1076 g:flag = false
1077 var l2: list<number> = g:flag
1078 ? [1, max([2, 3])]
1079 : [4, 5]
1080 assert_equal([4, 5], l2)
1081enddef
1082
1083def Test_min()
1084 g:flag = true
1085 var l1: list<number> = g:flag
1086 ? [1, min([2, 3])]
1087 : [4, 5]
1088 assert_equal([1, 2], l1)
1089
1090 g:flag = false
1091 var l2: list<number> = g:flag
1092 ? [1, min([2, 3])]
1093 : [4, 5]
1094 assert_equal([4, 5], l2)
1095enddef
1096
Bram Moolenaar94738d82020-10-21 14:25:07 +02001097def Test_nr2char()
1098 nr2char(97, true)->assert_equal('a')
1099enddef
1100
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001101def Test_or()
1102 CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1103 CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1104enddef
1105
Bram Moolenaar94738d82020-10-21 14:25:07 +02001106def Test_readdir()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001107 eval expand('sautest')->readdir((e) => e[0] !=# '.')
1108 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001109enddef
1110
Bram Moolenaarc423ad72021-01-13 20:38:03 +01001111def Test_readblob()
1112 var blob = 0z12341234
1113 writefile(blob, 'Xreadblob')
1114 var read: blob = readblob('Xreadblob')
1115 assert_equal(blob, read)
1116
1117 var lines =<< trim END
1118 var read: list<string> = readblob('Xreadblob')
1119 END
1120 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
1121 delete('Xreadblob')
1122enddef
1123
1124def Test_readfile()
1125 var text = ['aaa', 'bbb', 'ccc']
1126 writefile(text, 'Xreadfile')
1127 var read: list<string> = readfile('Xreadfile')
1128 assert_equal(text, read)
1129
1130 var lines =<< trim END
1131 var read: dict<string> = readfile('Xreadfile')
1132 END
1133 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
1134 delete('Xreadfile')
1135enddef
1136
Bram Moolenaar94738d82020-10-21 14:25:07 +02001137def Test_remove_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001138 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001139 var res = 0
1140 for n in l
1141 res += n
1142 endfor
1143 res->assert_equal(3)
1144enddef
1145
1146def Test_reverse_return_type()
1147 var l = reverse([1, 2, 3])
1148 var res = 0
1149 for n in l
1150 res += n
1151 endfor
1152 res->assert_equal(6)
1153enddef
1154
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001155def Test_screenattr()
1156 CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1157 CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1158enddef
1159
1160def Test_screenchar()
1161 CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1162 CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1163enddef
1164
1165def Test_screenchars()
1166 CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1167 CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1168enddef
1169
1170def Test_screenstring()
1171 CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1172 CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1173enddef
1174
Bram Moolenaar94738d82020-10-21 14:25:07 +02001175def Test_search()
1176 new
1177 setline(1, ['foo', 'bar'])
1178 var val = 0
1179 # skip expr returns boolean
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001180 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001181 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001182 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001183 # skip expr returns number, only 0 and 1 are accepted
1184 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001185 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001186 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001187 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
1188 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
1189 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001190
1191 setline(1, "find this word")
1192 normal gg
1193 var col = 7
1194 assert_equal(1, search('this', '', 0, 0, 'col(".") > col'))
1195 normal 0
1196 assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col'))
1197
1198 col = 5
1199 normal 0
1200 assert_equal(0, search('this', '', 0, 0, 'col(".") > col'))
1201 normal 0
1202 assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col'))
1203 bwipe!
Bram Moolenaar94738d82020-10-21 14:25:07 +02001204enddef
1205
1206def Test_searchcount()
1207 new
1208 setline(1, "foo bar")
1209 :/foo
Bram Moolenaare0de1712020-12-02 17:36:54 +01001210 searchcount({recompute: true})
1211 ->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001212 exact_match: 1,
1213 current: 1,
1214 total: 1,
1215 maxcount: 99,
1216 incomplete: 0})
1217 bwipe!
1218enddef
1219
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001220def Test_searchpair()
1221 new
1222 setline(1, "here { and } there")
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001223
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001224 normal f{
1225 var col = 15
1226 assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col'))
1227 assert_equal(12, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001228 normal 0f{
1229 assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col'))
1230
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001231 col = 8
1232 normal 0f{
1233 assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col'))
1234 assert_equal(6, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001235 normal 0f{
1236 assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col'))
1237
Bram Moolenaarff652882021-05-16 15:24:49 +02001238 var lines =<< trim END
1239 vim9script
1240 setline(1, '()')
1241 normal gg
1242 def Fail()
1243 try
1244 searchpairpos('(', '', ')', 'nW', '[0]->map("")')
1245 catch
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001246 g:caught = 'yes'
Bram Moolenaarff652882021-05-16 15:24:49 +02001247 endtry
1248 enddef
1249 Fail()
1250 END
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001251 CheckScriptSuccess(lines)
1252 assert_equal('yes', g:caught)
Bram Moolenaarff652882021-05-16 15:24:49 +02001253
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001254 unlet g:caught
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001255 bwipe!
1256enddef
1257
Bram Moolenaar34453202021-01-31 13:08:38 +01001258def Test_set_get_bufline()
1259 # similar to Test_setbufline_getbufline()
1260 var lines =<< trim END
1261 new
1262 var b = bufnr('%')
1263 hide
1264 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
1265 assert_equal(['foo'], getbufline(b, 1))
1266 assert_equal(['bar'], getbufline(b, '$'))
1267 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
1268 exe "bd!" b
1269 assert_equal([], getbufline(b, 1, 2))
1270
1271 split Xtest
1272 setline(1, ['a', 'b', 'c'])
1273 b = bufnr('%')
1274 wincmd w
1275
1276 assert_equal(1, setbufline(b, 5, 'x'))
1277 assert_equal(1, setbufline(b, 5, ['x']))
1278 assert_equal(1, setbufline(b, 5, []))
1279 assert_equal(1, setbufline(b, 5, test_null_list()))
1280
1281 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
1282 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
1283 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
1284 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
1285
1286 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
1287
1288 assert_equal(0, setbufline(b, 4, ['d', 'e']))
1289 assert_equal(['c'], b->getbufline(3))
1290 assert_equal(['d'], getbufline(b, 4))
1291 assert_equal(['e'], getbufline(b, 5))
1292 assert_equal([], getbufline(b, 6))
1293 assert_equal([], getbufline(b, 2, 1))
1294
Bram Moolenaar00385112021-02-07 14:31:06 +01001295 if has('job')
Bram Moolenaar1328bde2021-06-05 20:51:38 +02001296 setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())])
Bram Moolenaar00385112021-02-07 14:31:06 +01001297 assert_equal(["function('eval')",
1298 "{'key': 123}",
1299 "no process"],
1300 getbufline(b, 2, 4))
1301 endif
Bram Moolenaar34453202021-01-31 13:08:38 +01001302
1303 exe 'bwipe! ' .. b
1304 END
1305 CheckDefAndScriptSuccess(lines)
1306enddef
1307
Bram Moolenaar94738d82020-10-21 14:25:07 +02001308def Test_searchdecl()
1309 searchdecl('blah', true, true)->assert_equal(1)
1310enddef
1311
1312def Test_setbufvar()
1313 setbufvar(bufnr('%'), '&syntax', 'vim')
1314 &syntax->assert_equal('vim')
1315 setbufvar(bufnr('%'), '&ts', 16)
1316 &ts->assert_equal(16)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01001317 setbufvar(bufnr('%'), '&ai', true)
1318 &ai->assert_equal(true)
1319 setbufvar(bufnr('%'), '&ft', 'filetype')
1320 &ft->assert_equal('filetype')
1321
Bram Moolenaar94738d82020-10-21 14:25:07 +02001322 settabwinvar(1, 1, '&syntax', 'vam')
1323 &syntax->assert_equal('vam')
1324 settabwinvar(1, 1, '&ts', 15)
1325 &ts->assert_equal(15)
1326 setlocal ts=8
Bram Moolenaarb0d81822021-01-03 15:55:10 +01001327 settabwinvar(1, 1, '&list', false)
1328 &list->assert_equal(false)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01001329 settabwinvar(1, 1, '&list', true)
1330 &list->assert_equal(true)
1331 setlocal list&
Bram Moolenaar94738d82020-10-21 14:25:07 +02001332
1333 setbufvar('%', 'myvar', 123)
1334 getbufvar('%', 'myvar')->assert_equal(123)
1335enddef
1336
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001337def Test_setcmdpos()
1338 CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1339enddef
1340
Bram Moolenaar94738d82020-10-21 14:25:07 +02001341def Test_setloclist()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001342 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
1343 var what = {items: items}
Bram Moolenaar94738d82020-10-21 14:25:07 +02001344 setqflist([], ' ', what)
1345 setloclist(0, [], ' ', what)
1346enddef
1347
1348def Test_setreg()
1349 setreg('a', ['aaa', 'bbb', 'ccc'])
1350 var reginfo = getreginfo('a')
1351 setreg('a', reginfo)
1352 getreginfo('a')->assert_equal(reginfo)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001353 assert_fails('setreg("ab", 0)', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001354enddef
1355
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001356def Test_shiftwidth()
1357 CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1358enddef
1359
Bram Moolenaar6601b622021-01-13 21:47:15 +01001360def Test_slice()
1361 assert_equal('12345', slice('012345', 1))
1362 assert_equal('123', slice('012345', 1, 4))
1363 assert_equal('1234', slice('012345', 1, -1))
1364 assert_equal('1', slice('012345', 1, -4))
1365 assert_equal('', slice('012345', 1, -5))
1366 assert_equal('', slice('012345', 1, -6))
1367
1368 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
1369 assert_equal([1, 2, 3], slice(range(6), 1, 4))
1370 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
1371 assert_equal([1], slice(range(6), 1, -4))
1372 assert_equal([], slice(range(6), 1, -5))
1373 assert_equal([], slice(range(6), 1, -6))
1374
1375 assert_equal(0z1122334455, slice(0z001122334455, 1))
1376 assert_equal(0z112233, slice(0z001122334455, 1, 4))
1377 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
1378 assert_equal(0z11, slice(0z001122334455, 1, -4))
1379 assert_equal(0z, slice(0z001122334455, 1, -5))
1380 assert_equal(0z, slice(0z001122334455, 1, -6))
1381enddef
1382
Bram Moolenaar94738d82020-10-21 14:25:07 +02001383def Test_spellsuggest()
1384 if !has('spell')
1385 MissingFeature 'spell'
1386 else
1387 spellsuggest('marrch', 1, true)->assert_equal(['March'])
1388 endif
1389enddef
1390
1391def Test_sort_return_type()
1392 var res: list<number>
1393 res = [1, 2, 3]->sort()
1394enddef
1395
1396def Test_sort_argument()
Bram Moolenaar08cf0c02020-12-05 21:47:06 +01001397 var lines =<< trim END
1398 var res = ['b', 'a', 'c']->sort('i')
1399 res->assert_equal(['a', 'b', 'c'])
1400
1401 def Compare(a: number, b: number): number
1402 return a - b
1403 enddef
1404 var l = [3, 6, 7, 1, 8, 2, 4, 5]
1405 sort(l, Compare)
1406 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
1407 END
1408 CheckDefAndScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001409enddef
1410
1411def Test_split()
1412 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
1413enddef
1414
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01001415def Run_str2float()
1416 if !has('float')
1417 MissingFeature 'float'
1418 endif
1419 str2float("1.00")->assert_equal(1.00)
1420 str2float("2e-2")->assert_equal(0.02)
1421
1422 CheckDefFailure(['echo str2float(123)'], 'E1013:')
1423 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
1424 endif
1425enddef
1426
Bram Moolenaar94738d82020-10-21 14:25:07 +02001427def Test_str2nr()
1428 str2nr("1'000'000", 10, true)->assert_equal(1000000)
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01001429
1430 CheckDefFailure(['echo str2nr(123)'], 'E1013:')
1431 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
1432 CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:')
1433 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
1434 CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:')
1435 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001436enddef
1437
1438def Test_strchars()
1439 strchars("A\u20dd", true)->assert_equal(1)
1440enddef
1441
1442def Test_submatch()
1443 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
Bram Moolenaar75ab91f2021-01-10 22:42:50 +01001444 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001445 var actual = substitute('A123456789', pat, Rep, '')
1446 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
1447 actual->assert_equal(expected)
1448enddef
1449
Bram Moolenaar1328bde2021-06-05 20:51:38 +02001450def Test_substitute()
1451 var res = substitute('A1234', '\d', 'X', '')
1452 assert_equal('AX234', res)
1453
1454 if has('job')
1455 assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job')
1456 assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel')
1457 endif
1458enddef
1459
Bram Moolenaar94738d82020-10-21 14:25:07 +02001460def Test_synID()
1461 new
1462 setline(1, "text")
1463 synID(1, 1, true)->assert_equal(0)
1464 bwipe!
1465enddef
1466
1467def Test_term_gettty()
1468 if !has('terminal')
1469 MissingFeature 'terminal'
1470 else
1471 var buf = Run_shell_in_terminal({})
1472 term_gettty(buf, true)->assert_notequal('')
1473 StopShellInTerminal(buf)
1474 endif
1475enddef
1476
1477def Test_term_start()
1478 if !has('terminal')
1479 MissingFeature 'terminal'
1480 else
1481 botright new
1482 var winnr = winnr()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001483 term_start(&shell, {curwin: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001484 winnr()->assert_equal(winnr)
1485 bwipe!
1486 endif
1487enddef
1488
1489def Test_timer_paused()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001490 var id = timer_start(50, () => 0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001491 timer_pause(id, true)
1492 var info = timer_info(id)
1493 info[0]['paused']->assert_equal(1)
1494 timer_stop(id)
1495enddef
1496
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001497def Test_tolower()
1498 CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1499enddef
1500
1501def Test_toupper()
1502 CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1503enddef
1504
1505def Test_tr()
1506 CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1507 CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1508 CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1509enddef
1510
Bram Moolenaar37487e12021-01-12 22:08:53 +01001511def Test_win_execute()
1512 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
1513 assert_equal('', win_execute(342343, 'echo winnr()'))
1514enddef
1515
Bram Moolenaar94738d82020-10-21 14:25:07 +02001516def Test_win_splitmove()
1517 split
Bram Moolenaare0de1712020-12-02 17:36:54 +01001518 win_splitmove(1, 2, {vertical: true, rightbelow: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001519 close
1520enddef
1521
Bram Moolenaar285b15f2020-12-29 20:25:19 +01001522def Test_winrestcmd()
1523 split
1524 var cmd = winrestcmd()
1525 wincmd _
1526 exe cmd
1527 assert_equal(cmd, winrestcmd())
1528 close
1529enddef
1530
Bram Moolenaar43b69b32021-01-07 20:23:33 +01001531def Test_winsaveview()
1532 var view: dict<number> = winsaveview()
1533
1534 var lines =<< trim END
1535 var view: list<number> = winsaveview()
1536 END
1537 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
1538enddef
1539
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001540def Test_win_gettype()
1541 CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1542enddef
Bram Moolenaar43b69b32021-01-07 20:23:33 +01001543
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001544def Test_win_gotoid()
1545 CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1546enddef
Bram Moolenaar285b15f2020-12-29 20:25:19 +01001547
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001548def Test_win_id2tabwin()
1549 CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1550enddef
1551
1552def Test_win_id2win()
1553 CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1554enddef
1555
1556def Test_win_screenpos()
1557 CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1558enddef
1559
1560def Test_winbufnr()
1561 CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1562enddef
1563
1564def Test_winheight()
1565 CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1566enddef
1567
1568def Test_winlayout()
1569 CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1570enddef
1571
1572def Test_winwidth()
1573 CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1574enddef
1575
1576def Test_xor()
1577 CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1578 CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1579enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02001580
1581" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker