blob: dcf60072f10cb4cf461d5aa2381e7a8ffdad59e2 [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 Moolenaarf32f0992021-07-08 20:53:40 +0200107
108 lines =<< trim END
109 vim9script
110 var l: list<string> = ['a']
111 l->add(123)
112 END
113 CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
Bram Moolenaarf055d452021-07-08 20:57:24 +0200114
115 lines =<< trim END
116 vim9script
117 var l: list<string>
118 l->add(123)
119 END
120 CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200121enddef
122
123def Test_add_blob()
124 var b1: blob = 0z12
125 add(b1, 0x34)
126 assert_equal(0z1234, b1)
127
128 var b2: blob # defaults to empty blob
129 add(b2, 0x67)
130 assert_equal(0z67, b2)
131
132 var lines =<< trim END
133 var b: blob
134 add(b, "x")
135 END
136 CheckDefFailure(lines, 'E1012:', 2)
137
138 lines =<< trim END
Bram Moolenaarb7c21af2021-04-18 14:12:31 +0200139 add(test_null_blob(), 123)
140 END
141 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
142
143 lines =<< trim END
Bram Moolenaar94738d82020-10-21 14:25:07 +0200144 var b: blob = test_null_blob()
145 add(b, 123)
146 END
147 CheckDefExecFailure(lines, 'E1131:', 2)
Bram Moolenaarb7c21af2021-04-18 14:12:31 +0200148
149 # Getting variable with NULL blob allocates a new blob at script level
150 lines =<< trim END
151 vim9script
152 var b: blob = test_null_blob()
153 add(b, 123)
154 END
155 CheckScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200156enddef
157
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200158def Test_and()
159 CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
160 CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
161enddef
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))
174 bwipe!
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100175enddef
176
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200177def Test_argc()
178 CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
179enddef
180
181def Test_arglistid()
182 CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
183 CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string')
184 CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
185enddef
186
187def Test_argv()
188 CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
189 CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
190 CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
191enddef
192
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100193def Test_balloon_show()
194 CheckGui
195 CheckFeature balloon_eval
196
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200197 assert_fails('balloon_show(10)', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100198 assert_fails('balloon_show(true)', 'E1174:')
199enddef
200
201def Test_balloon_split()
Bram Moolenaar7b45d462021-03-27 19:09:02 +0100202 CheckFeature balloon_eval_term
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100203
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200204 assert_fails('balloon_split([])', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100205 assert_fails('balloon_split(true)', 'E1174:')
206enddef
207
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100208def Test_browse()
209 CheckFeature browse
210
211 var lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100212 browse(1, 2, 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100213 END
214 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
215 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100216 browse(1, 'title', 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100217 END
218 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
219 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100220 browse(1, 'title', 'dir', 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100221 END
222 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
223enddef
224
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200225def Test_bufadd()
226 assert_fails('bufadd([])', 'E730:')
227enddef
228
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100229def Test_bufexists()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200230 assert_fails('bufexists(true)', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100231enddef
232
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100233def Test_buflisted()
234 var res: bool = buflisted('asdf')
235 assert_equal(false, res)
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200236 assert_fails('buflisted(true)', 'E1174:')
237 assert_fails('buflisted([])', 'E1174:')
238enddef
239
240def Test_bufload()
241 assert_fails('bufload([])', 'E730:')
242enddef
243
244def Test_bufloaded()
245 assert_fails('bufloaded(true)', 'E1174:')
246 assert_fails('bufloaded([])', 'E1174:')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100247enddef
248
Bram Moolenaar94738d82020-10-21 14:25:07 +0200249def Test_bufname()
250 split SomeFile
251 bufname('%')->assert_equal('SomeFile')
252 edit OtherFile
253 bufname('#')->assert_equal('SomeFile')
254 close
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200255 assert_fails('bufname(true)', 'E1138:')
256 assert_fails('bufname([])', 'E745:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200257enddef
258
259def Test_bufnr()
260 var buf = bufnr()
261 bufnr('%')->assert_equal(buf)
262
263 buf = bufnr('Xdummy', true)
264 buf->assert_notequal(-1)
265 exe 'bwipe! ' .. buf
266enddef
267
268def Test_bufwinid()
269 var origwin = win_getid()
270 below split SomeFile
271 var SomeFileID = win_getid()
272 below split OtherFile
273 below split SomeFile
274 bufwinid('SomeFile')->assert_equal(SomeFileID)
275
276 win_gotoid(origwin)
277 only
278 bwipe SomeFile
279 bwipe OtherFile
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100280
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200281 assert_fails('bufwinid(true)', 'E1138:')
282 assert_fails('bufwinid([])', 'E745:')
283enddef
284
285def Test_bufwinnr()
286 assert_fails('bufwinnr(true)', 'E1138:')
287 assert_fails('bufwinnr([])', 'E745:')
288enddef
289
290def Test_byte2line()
291 CheckDefFailure(['byte2line("1")'], 'E1013: Argument 1: type mismatch, expected number but got string')
292 CheckDefFailure(['byte2line([])'], 'E1013: Argument 1: type mismatch, expected number but got list<unknown>')
293 assert_equal(-1, byte2line(0))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200294enddef
295
296def Test_call_call()
297 var l = [3, 2, 1]
298 call('reverse', [l])
299 l->assert_equal([1, 2, 3])
300enddef
301
Bram Moolenaarc5809432021-03-27 21:23:30 +0100302def Test_ch_logfile()
Bram Moolenaar886e5e72021-04-05 13:36:34 +0200303 if !has('channel')
304 CheckFeature channel
305 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200306 assert_fails('ch_logfile(true)', 'E1174:')
307 assert_fails('ch_logfile("foo", true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100308enddef
309
Bram Moolenaar94738d82020-10-21 14:25:07 +0200310def Test_char2nr()
311 char2nr('あ', true)->assert_equal(12354)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100312
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200313 assert_fails('char2nr(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100314enddef
315
316def Test_charclass()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200317 assert_fails('charclass(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100318enddef
319
320def Test_chdir()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200321 assert_fails('chdir(true)', 'E1174:')
322enddef
323
324def Test_cindent()
325 CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
326 CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
327 assert_equal(-1, cindent(0))
328 assert_equal(0, cindent('.'))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200329enddef
330
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200331def Test_clearmatches()
332 CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
333enddef
334
Bram Moolenaar94738d82020-10-21 14:25:07 +0200335def Test_col()
336 new
337 setline(1, 'asdf')
338 col([1, '$'])->assert_equal(5)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100339
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200340 assert_fails('col(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100341enddef
342
343def Test_confirm()
344 if !has('dialog_con') && !has('dialog_gui')
345 CheckFeature dialog_con
346 endif
347
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200348 assert_fails('confirm(true)', 'E1174:')
349 assert_fails('confirm("yes", true)', 'E1174:')
350 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:')
351enddef
352
353def Test_complete_info()
354 CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
355 CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>')
356 assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info())
357 assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items']))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200358enddef
359
360def Test_copy_return_type()
361 var l = copy([1, 2, 3])
362 var res = 0
363 for n in l
364 res += n
365 endfor
366 res->assert_equal(6)
367
368 var dl = deepcopy([1, 2, 3])
369 res = 0
370 for n in dl
371 res += n
372 endfor
373 res->assert_equal(6)
374
375 dl = deepcopy([1, 2, 3], true)
376enddef
377
378def Test_count()
379 count('ABC ABC ABC', 'b', true)->assert_equal(3)
380 count('ABC ABC ABC', 'b', false)->assert_equal(0)
381enddef
382
Bram Moolenaar9a963372020-12-21 21:58:46 +0100383def Test_cursor()
384 new
385 setline(1, range(4))
386 cursor(2, 1)
387 assert_equal(2, getcurpos()[1])
388 cursor('$', 1)
389 assert_equal(4, getcurpos()[1])
390
391 var lines =<< trim END
392 cursor('2', 1)
393 END
394 CheckDefExecAndScriptFailure(lines, 'E475:')
395enddef
396
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200397def Test_debugbreak()
398 CheckMSWindows
399 CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
400enddef
401
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100402def Test_delete()
403 var res: bool = delete('doesnotexist')
404 assert_equal(true, res)
405enddef
406
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200407def Test_diff_filler()
408 CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
409 CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
410 assert_equal(0, diff_filler(1))
411 assert_equal(0, diff_filler('.'))
412enddef
413
414def Test_escape()
415 CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
416 CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number')
417 CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
418 assert_equal('a\:b', escape("a:b", ":"))
419enddef
420
421def Test_eval()
422 CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
423 CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
424 assert_equal(2, eval('1 + 1'))
425enddef
426
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100427def Test_executable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100428 assert_false(executable(""))
429 assert_false(executable(test_null_string()))
430
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200431 CheckDefExecFailure(['echo executable(123)'], 'E1013:')
432 CheckDefExecFailure(['echo executable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100433enddef
434
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200435def Test_execute()
436 var res = execute("echo 'hello'")
437 assert_equal("\nhello", res)
438 res = execute(["echo 'here'", "echo 'there'"])
439 assert_equal("\nhere\nthere", res)
440
441 CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
442 CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
443 CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
444 CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
445enddef
446
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100447def Test_exepath()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200448 CheckDefExecFailure(['echo exepath(true)'], 'E1013:')
449 CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100450 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100451enddef
452
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200453def Test_exists()
454 CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
455 call assert_equal(1, exists('&tabstop'))
456enddef
457
Bram Moolenaar94738d82020-10-21 14:25:07 +0200458def Test_expand()
459 split SomeFile
460 expand('%', true, true)->assert_equal(['SomeFile'])
461 close
462enddef
463
Bram Moolenaar02795102021-05-03 21:40:26 +0200464def Test_expandcmd()
465 $FOO = "blue"
466 assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
467
468 assert_equal("yes", expandcmd("`={a: 'yes'}['a']`"))
469enddef
470
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100471def Test_extend_arg_types()
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100472 g:number_one = 1
473 g:string_keep = 'keep'
474 var lines =<< trim END
475 assert_equal([1, 2, 3], extend([1, 2], [3]))
476 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
477 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
478 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100479
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100480 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
481 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
482 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
483 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100484
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100485 var res: list<dict<any>>
486 extend(res, mapnew([1, 2], (_, v) => ({})))
487 assert_equal([{}, {}], res)
488 END
489 CheckDefAndScriptSuccess(lines)
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100490
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200491 CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100492 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
493 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
494 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
495
Bram Moolenaare0de1712020-12-02 17:36:54 +0100496 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
497 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
498 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
Bram Moolenaar351ead02021-01-16 16:07:01 +0100499
500 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
Bram Moolenaare32e5162021-01-21 20:21:29 +0100501 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100502enddef
503
Bram Moolenaarb0e6b512021-01-12 20:23:40 +0100504def Test_extendnew()
505 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
506 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
507
508 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
509 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
510 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
511 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
512enddef
513
Bram Moolenaar94738d82020-10-21 14:25:07 +0200514def Test_extend_return_type()
515 var l = extend([1, 2], [3])
516 var res = 0
517 for n in l
518 res += n
519 endfor
520 res->assert_equal(6)
521enddef
522
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100523func g:ExtendDict(d)
524 call extend(a:d, #{xx: 'x'})
525endfunc
526
527def Test_extend_dict_item_type()
528 var lines =<< trim END
529 var d: dict<number> = {a: 1}
530 extend(d, {b: 2})
531 END
532 CheckDefAndScriptSuccess(lines)
533
534 lines =<< trim END
535 var d: dict<number> = {a: 1}
536 extend(d, {b: 'x'})
537 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100538 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100539
540 lines =<< trim END
541 var d: dict<number> = {a: 1}
542 g:ExtendDict(d)
543 END
544 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
545 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
546enddef
547
548func g:ExtendList(l)
549 call extend(a:l, ['x'])
550endfunc
551
552def Test_extend_list_item_type()
553 var lines =<< trim END
554 var l: list<number> = [1]
555 extend(l, [2])
556 END
557 CheckDefAndScriptSuccess(lines)
558
559 lines =<< trim END
560 var l: list<number> = [1]
561 extend(l, ['x'])
562 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100563 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100564
565 lines =<< trim END
566 var l: list<number> = [1]
567 g:ExtendList(l)
568 END
569 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
570 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
571enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200572
Bram Moolenaar93e1cae2021-03-13 21:24:56 +0100573def Test_extend_with_error_function()
574 var lines =<< trim END
575 vim9script
576 def F()
577 {
578 var m = 10
579 }
580 echo m
581 enddef
582
583 def Test()
584 var d: dict<any> = {}
585 d->extend({A: 10, Func: function('F', [])})
586 enddef
587
588 Test()
589 END
590 CheckScriptFailure(lines, 'E1001: Variable not found: m')
591enddef
592
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200593def Test_feedkeys()
594 CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
595 CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
596 CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
597 g:TestVar = 1
598 feedkeys(":g:TestVar = 789\n", 'xt')
599 assert_equal(789, g:TestVar)
600 unlet g:TestVar
601enddef
602
Bram Moolenaar64ed4d42021-01-12 21:22:31 +0100603def Test_job_info_return_type()
604 if has('job')
605 job_start(&shell)
606 var jobs = job_info()
Bram Moolenaara47e05f2021-01-12 21:49:00 +0100607 assert_equal('list<job>', typename(jobs))
608 assert_equal('dict<any>', typename(job_info(jobs[0])))
Bram Moolenaar64ed4d42021-01-12 21:22:31 +0100609 job_stop(jobs[0])
610 endif
611enddef
612
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100613def Test_filereadable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100614 assert_false(filereadable(""))
615 assert_false(filereadable(test_null_string()))
616
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200617 CheckDefExecFailure(['echo filereadable(123)'], 'E1013:')
618 CheckDefExecFailure(['echo filereadable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100619enddef
620
621def Test_filewritable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100622 assert_false(filewritable(""))
623 assert_false(filewritable(test_null_string()))
624
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200625 CheckDefExecFailure(['echo filewritable(123)'], 'E1013:')
626 CheckDefExecFailure(['echo filewritable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100627enddef
628
629def Test_finddir()
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100630 CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
631 CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100632 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100633enddef
634
635def Test_findfile()
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100636 CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
637 CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100638 CheckDefExecFailure(['echo findfile("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100639enddef
640
Bram Moolenaar3b690062021-02-01 20:14:51 +0100641def Test_flattennew()
642 var lines =<< trim END
643 var l = [1, [2, [3, 4]], 5]
644 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
645 call assert_equal([1, [2, [3, 4]], 5], l)
646
647 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
648 call assert_equal([1, [2, [3, 4]], 5], l)
649 END
650 CheckDefAndScriptSuccess(lines)
651
652 lines =<< trim END
653 echo flatten([1, 2, 3])
654 END
655 CheckDefAndScriptFailure(lines, 'E1158:')
656enddef
657
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200658" Test for float functions argument type
659def Test_float_funcs_args()
660 CheckFeature float
661
662 # acos()
663 CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
664 # asin()
665 CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
666 # atan()
667 CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
668 # atan2()
669 CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
670 CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
671 CheckDefFailure(['echo atan2(1.2)'], 'E119:')
672 # ceil()
673 CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
674 # cos()
675 CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
676 # cosh()
677 CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
678 # exp()
679 CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
680 # float2nr()
681 CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
682 # floor()
683 CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
684 # fmod()
685 CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
686 CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
687 CheckDefFailure(['echo fmod(1.1)'], 'E119:')
688 # isinf()
689 CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
690 # isnan()
691 CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
692 # log()
693 CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
694 # log10()
695 CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
696 # pow()
697 CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
698 CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
699 CheckDefFailure(['echo pow(1.1)'], 'E119:')
700 # round()
701 CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
702 # sin()
703 CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
704 # sinh()
705 CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
706 # sqrt()
707 CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
708 # tan()
709 CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
710 # tanh()
711 CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
712 # trunc()
713 CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
714enddef
715
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200716def Test_fnameescape()
717 CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
718 assert_equal('\+a\%b\|', fnameescape('+a%b|'))
719enddef
720
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100721def Test_fnamemodify()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100722 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
723 CheckDefSuccess(['echo fnamemodify("", ":p")'])
724 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
725 CheckDefSuccess(['echo fnamemodify("file", "")'])
726
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200727 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool')
728 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special')
729 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100730enddef
731
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100732def Wrong_dict_key_type(items: list<number>): list<number>
733 return filter(items, (_, val) => get({[val]: 1}, 'x'))
734enddef
735
Bram Moolenaar94738d82020-10-21 14:25:07 +0200736def Test_filter_wrong_dict_key_type()
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100737 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200738enddef
739
740def Test_filter_return_type()
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200741 var l = filter([1, 2, 3], (_, _) => 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200742 var res = 0
743 for n in l
744 res += n
745 endfor
746 res->assert_equal(6)
747enddef
748
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100749def Test_filter_missing_argument()
750 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200751 var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100752 res->assert_equal({aa: [1], ac: [3]})
753enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200754
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200755def Test_foldclosed()
756 CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any')
757 assert_equal(-1, foldclosed(1))
758 assert_equal(-1, foldclosed('$'))
759enddef
760
761def Test_foldclosedend()
762 CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
763 assert_equal(-1, foldclosedend(1))
764 assert_equal(-1, foldclosedend('w0'))
765enddef
766
767def Test_foldlevel()
768 CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
769 assert_equal(0, foldlevel(1))
770 assert_equal(0, foldlevel('.'))
771enddef
772
773def Test_foldtextresult()
774 CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
775 assert_equal('', foldtextresult(1))
776 assert_equal('', foldtextresult('.'))
777enddef
778
Bram Moolenaar7d840e92021-05-26 21:10:11 +0200779def Test_fullcommand()
780 assert_equal('next', fullcommand('n'))
781 assert_equal('noremap', fullcommand('no'))
782 assert_equal('noremap', fullcommand('nor'))
783 assert_equal('normal', fullcommand('norm'))
784
785 assert_equal('', fullcommand('k'))
786 assert_equal('keepmarks', fullcommand('ke'))
787 assert_equal('keepmarks', fullcommand('kee'))
788 assert_equal('keepmarks', fullcommand('keep'))
789 assert_equal('keepjumps', fullcommand('keepj'))
790
791 assert_equal('dlist', fullcommand('dl'))
792 assert_equal('', fullcommand('dp'))
793 assert_equal('delete', fullcommand('del'))
794 assert_equal('', fullcommand('dell'))
795 assert_equal('', fullcommand('delp'))
796
797 assert_equal('srewind', fullcommand('sre'))
798 assert_equal('scriptnames', fullcommand('scr'))
799 assert_equal('', fullcommand('scg'))
800enddef
801
Bram Moolenaar94738d82020-10-21 14:25:07 +0200802def Test_garbagecollect()
803 garbagecollect(true)
804enddef
805
806def Test_getbufinfo()
807 var bufinfo = getbufinfo(bufnr())
808 getbufinfo('%')->assert_equal(bufinfo)
809
810 edit Xtestfile1
811 hide edit Xtestfile2
812 hide enew
Bram Moolenaare0de1712020-12-02 17:36:54 +0100813 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200814 ->len()->assert_equal(3)
815 bwipe Xtestfile1 Xtestfile2
816enddef
817
818def Test_getbufline()
819 e SomeFile
820 var buf = bufnr()
821 e #
822 var lines = ['aaa', 'bbb', 'ccc']
823 setbufline(buf, 1, lines)
824 getbufline('#', 1, '$')->assert_equal(lines)
Bram Moolenaare6e70a12020-10-22 18:23:38 +0200825 getbufline(-1, '$', '$')->assert_equal([])
826 getbufline(-1, 1, '$')->assert_equal([])
Bram Moolenaar94738d82020-10-21 14:25:07 +0200827
828 bwipe!
829enddef
830
831def Test_getchangelist()
832 new
833 setline(1, 'some text')
834 var changelist = bufnr()->getchangelist()
835 getchangelist('%')->assert_equal(changelist)
836 bwipe!
837enddef
838
839def Test_getchar()
840 while getchar(0)
841 endwhile
842 getchar(true)->assert_equal(0)
843enddef
844
Bram Moolenaar7ad67d12021-03-10 16:08:26 +0100845def Test_getenv()
846 if getenv('does-not_exist') == ''
847 assert_report('getenv() should return null')
848 endif
849 if getenv('does-not_exist') == null
850 else
851 assert_report('getenv() should return null')
852 endif
853 $SOMEENVVAR = 'some'
854 assert_equal('some', getenv('SOMEENVVAR'))
855 unlet $SOMEENVVAR
856enddef
857
Bram Moolenaar94738d82020-10-21 14:25:07 +0200858def Test_getcompletion()
859 set wildignore=*.vim,*~
860 var l = getcompletion('run', 'file', true)
861 l->assert_equal([])
862 set wildignore&
863enddef
864
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200865def Test_getcurpos()
866 CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
867enddef
868
869def Test_getcursorcharpos()
870 CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
871enddef
872
873def Test_getcwd()
874 CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
875 CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
876 CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
877enddef
878
Bram Moolenaar94738d82020-10-21 14:25:07 +0200879def Test_getloclist_return_type()
880 var l = getloclist(1)
881 l->assert_equal([])
882
Bram Moolenaare0de1712020-12-02 17:36:54 +0100883 var d = getloclist(1, {items: 0})
884 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200885enddef
886
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200887def Test_getfontname()
888 CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
889enddef
890
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100891def Test_getfperm()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100892 assert_equal('', getfperm(""))
893 assert_equal('', getfperm(test_null_string()))
894
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200895 CheckDefExecFailure(['echo getfperm(true)'], 'E1013:')
896 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100897enddef
898
899def Test_getfsize()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100900 assert_equal(-1, getfsize(""))
901 assert_equal(-1, getfsize(test_null_string()))
902
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200903 CheckDefExecFailure(['echo getfsize(true)'], 'E1013:')
904 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100905enddef
906
907def Test_getftime()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100908 assert_equal(-1, getftime(""))
909 assert_equal(-1, getftime(test_null_string()))
910
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200911 CheckDefExecFailure(['echo getftime(true)'], 'E1013:')
912 CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100913enddef
914
915def Test_getftype()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100916 assert_equal('', getftype(""))
917 assert_equal('', getftype(test_null_string()))
918
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200919 CheckDefExecFailure(['echo getftype(true)'], 'E1013:')
920 CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100921enddef
922
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200923def Test_getjumplist()
924 CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
925 CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
926 CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
927enddef
928
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200929def Test_getmarklist()
930 CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
931 assert_equal([], getmarklist(10000))
932 assert_fails('getmarklist("a%b@#")', 'E94:')
933enddef
934
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200935def Test_getmatches()
936 CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
937enddef
938
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200939def Test_getpos()
940 CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
941 assert_equal([0, 1, 1, 0], getpos('.'))
942 assert_equal([0, 0, 0, 0], getpos('a'))
943enddef
944
945def Test_getqflist()
946 CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
947 call assert_equal({}, getqflist({}))
948enddef
949
Bram Moolenaar94738d82020-10-21 14:25:07 +0200950def Test_getqflist_return_type()
951 var l = getqflist()
952 l->assert_equal([])
953
Bram Moolenaare0de1712020-12-02 17:36:54 +0100954 var d = getqflist({items: 0})
955 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +0200956enddef
957
958def Test_getreg()
959 var lines = ['aaa', 'bbb', 'ccc']
960 setreg('a', lines)
961 getreg('a', true, true)->assert_equal(lines)
Bram Moolenaar418a29f2021-02-10 22:23:41 +0100962 assert_fails('getreg("ab")', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200963enddef
964
965def Test_getreg_return_type()
966 var s1: string = getreg('"')
967 var s2: string = getreg('"', 1)
968 var s3: list<string> = getreg('"', 1, 1)
969enddef
970
Bram Moolenaar418a29f2021-02-10 22:23:41 +0100971def Test_getreginfo()
972 var text = 'abc'
973 setreg('a', text)
974 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
975 assert_fails('getreginfo("ab")', 'E1162:')
976enddef
977
978def Test_getregtype()
979 var lines = ['aaa', 'bbb', 'ccc']
980 setreg('a', lines)
981 getregtype('a')->assert_equal('V')
982 assert_fails('getregtype("ab")', 'E1162:')
983enddef
984
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200985def Test_gettabinfo()
986 CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
987enddef
988
989def Test_gettagstack()
990 CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
991enddef
992
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200993def Test_gettext()
994 CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
995 assert_equal('abc', gettext("abc"))
996enddef
997
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200998def Test_getwininfo()
999 CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1000enddef
1001
1002def Test_getwinpos()
1003 CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1004enddef
1005
Bram Moolenaar94738d82020-10-21 14:25:07 +02001006def Test_glob()
1007 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
1008enddef
1009
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001010def Test_glob2regpat()
1011 CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1012 assert_equal('^$', glob2regpat(''))
1013enddef
1014
Bram Moolenaar94738d82020-10-21 14:25:07 +02001015def Test_globpath()
1016 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
1017enddef
1018
1019def Test_has()
1020 has('eval', true)->assert_equal(1)
1021enddef
1022
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001023def Test_haslocaldir()
1024 CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1025 CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1026 CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1027enddef
1028
Bram Moolenaar94738d82020-10-21 14:25:07 +02001029def Test_hasmapto()
1030 hasmapto('foobar', 'i', true)->assert_equal(0)
1031 iabbrev foo foobar
1032 hasmapto('foobar', 'i', true)->assert_equal(1)
1033 iunabbrev foo
1034enddef
1035
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001036def Test_histadd()
1037 CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1038 CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1039 histadd("search", 'skyblue')
1040 assert_equal('skyblue', histget('/', -1))
1041enddef
1042
1043def Test_histnr()
1044 CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1045 assert_equal(-1, histnr('abc'))
1046enddef
1047
1048def Test_hlID()
1049 CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1050 assert_equal(0, hlID('NonExistingHighlight'))
1051enddef
1052
1053def Test_hlexists()
1054 CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1055 assert_equal(0, hlexists('NonExistingHighlight'))
1056enddef
1057
1058def Test_iconv()
1059 CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1060 CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1061 CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1062 assert_equal('abc', iconv('abc', 'fromenc', 'toenc'))
1063enddef
1064
Bram Moolenaar94738d82020-10-21 14:25:07 +02001065def Test_index()
1066 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
1067enddef
1068
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001069def Test_inputlist()
1070 CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number')
1071 CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
1072 CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
1073 feedkeys("2\<CR>", 't')
1074 var r: number = inputlist(['a', 'b', 'c'])
1075 assert_equal(2, r)
1076enddef
1077
1078def Test_inputsecret()
1079 CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1080 CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1081 feedkeys("\<CR>", 't')
1082 var ans: string = inputsecret('Pass:', '123')
1083 assert_equal('123', ans)
1084enddef
1085
Bram Moolenaar193f6202020-11-16 20:08:35 +01001086let s:number_one = 1
1087let s:number_two = 2
1088let s:string_keep = 'keep'
1089
Bram Moolenaarca174532020-10-21 16:42:22 +02001090def Test_insert()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001091 var l = insert([2, 1], 3)
1092 var res = 0
1093 for n in l
1094 res += n
1095 endfor
1096 res->assert_equal(6)
Bram Moolenaarca174532020-10-21 16:42:22 +02001097
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001098 var m: any = []
1099 insert(m, 4)
1100 call assert_equal([4], m)
1101 extend(m, [6], 0)
1102 call assert_equal([6, 4], m)
1103
Bram Moolenaar39211cb2021-04-18 15:48:04 +02001104 var lines =<< trim END
1105 insert(test_null_list(), 123)
1106 END
1107 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
1108
1109 lines =<< trim END
1110 insert(test_null_blob(), 123)
1111 END
1112 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
1113
Bram Moolenaarca174532020-10-21 16:42:22 +02001114 assert_equal([1, 2, 3], insert([2, 3], 1))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001115 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
Bram Moolenaarca174532020-10-21 16:42:22 +02001116 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001117 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
Bram Moolenaarca174532020-10-21 16:42:22 +02001118 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
1119 assert_equal(0z1234, insert(0z34, 0x12))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001120
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001121 CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
Bram Moolenaarca174532020-10-21 16:42:22 +02001122 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
1123 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001124enddef
1125
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001126def Test_invert()
1127 CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1128enddef
1129
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001130def Test_isdirectory()
1131 CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
1132 assert_false(isdirectory('NonExistingDir'))
1133enddef
1134
1135def Test_items()
1136 CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1137 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items())
1138 assert_equal([], {}->items())
1139enddef
1140
1141def Test_js_decode()
1142 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1143 assert_equal([1, 2], js_decode('[1,2]'))
1144enddef
1145
1146def Test_json_decode()
1147 CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1148 assert_equal(1.0, json_decode('1.0'))
1149enddef
1150
1151def Test_keys()
1152 CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1153 assert_equal(['a'], {a: 'v'}->keys())
1154 assert_equal([], {}->keys())
1155enddef
1156
Bram Moolenaar94738d82020-10-21 14:25:07 +02001157def Test_keys_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001158 const var: list<string> = {a: 1, b: 2}->keys()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001159 var->assert_equal(['a', 'b'])
1160enddef
1161
Bram Moolenaarc5809432021-03-27 21:23:30 +01001162def Test_line()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001163 assert_fails('line(true)', 'E1174:')
1164enddef
1165
1166def Test_line2byte()
1167 CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1168 assert_equal(-1, line2byte(1))
1169 assert_equal(-1, line2byte(10000))
1170enddef
1171
1172def Test_lispindent()
1173 CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1174 assert_equal(0, lispindent(1))
Bram Moolenaarc5809432021-03-27 21:23:30 +01001175enddef
1176
Bram Moolenaar94738d82020-10-21 14:25:07 +02001177def Test_list2str_str2list_utf8()
1178 var s = "\u3042\u3044"
1179 var l = [0x3042, 0x3044]
1180 str2list(s, true)->assert_equal(l)
1181 list2str(l, true)->assert_equal(s)
1182enddef
1183
1184def SID(): number
1185 return expand('<SID>')
1186 ->matchstr('<SNR>\zs\d\+\ze_$')
1187 ->str2nr()
1188enddef
1189
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001190def Test_listener_remove()
1191 CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1192enddef
1193
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001194def Test_map_function_arg()
1195 var lines =<< trim END
1196 def MapOne(i: number, v: string): string
1197 return i .. ':' .. v
1198 enddef
1199 var l = ['a', 'b', 'c']
1200 map(l, MapOne)
1201 assert_equal(['0:a', '1:b', '2:c'], l)
1202 END
1203 CheckDefAndScriptSuccess(lines)
Bram Moolenaar8da6d6d2021-06-05 18:15:09 +02001204
1205 lines =<< trim END
1206 range(3)->map((a, b, c) => a + b + c)
1207 END
1208 CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
1209 lines =<< trim END
1210 range(3)->map((a, b, c, d) => a + b + c + d)
1211 END
1212 CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001213enddef
1214
1215def Test_map_item_type()
1216 var lines =<< trim END
1217 var l = ['a', 'b', 'c']
1218 map(l, (k, v) => k .. '/' .. v )
1219 assert_equal(['0/a', '1/b', '2/c'], l)
1220 END
1221 CheckDefAndScriptSuccess(lines)
1222
1223 lines =<< trim END
1224 var l: list<number> = [0]
1225 echo map(l, (_, v) => [])
1226 END
1227 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1228
1229 lines =<< trim END
1230 var l: list<number> = range(2)
1231 echo map(l, (_, v) => [])
1232 END
1233 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1234
1235 lines =<< trim END
1236 var d: dict<number> = {key: 0}
1237 echo map(d, (_, v) => [])
1238 END
1239 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1240enddef
1241
Bram Moolenaar94738d82020-10-21 14:25:07 +02001242def Test_maparg()
1243 var lnum = str2nr(expand('<sflnum>'))
1244 map foo bar
Bram Moolenaare0de1712020-12-02 17:36:54 +01001245 maparg('foo', '', false, true)->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001246 lnum: lnum + 1,
1247 script: 0,
1248 mode: ' ',
1249 silent: 0,
1250 noremap: 0,
1251 lhs: 'foo',
1252 lhsraw: 'foo',
1253 nowait: 0,
1254 expr: 0,
1255 sid: SID(),
1256 rhs: 'bar',
1257 buffer: 0})
1258 unmap foo
1259enddef
1260
1261def Test_mapcheck()
1262 iabbrev foo foobar
1263 mapcheck('foo', 'i', true)->assert_equal('foobar')
1264 iunabbrev foo
1265enddef
1266
1267def Test_maparg_mapset()
1268 nnoremap <F3> :echo "hit F3"<CR>
1269 var mapsave = maparg('<F3>', 'n', false, true)
1270 mapset('n', false, mapsave)
1271
1272 nunmap <F3>
1273enddef
1274
Bram Moolenaar027c4ab2021-02-21 16:20:18 +01001275def Test_map_failure()
1276 CheckFeature job
1277
1278 var lines =<< trim END
1279 vim9script
1280 writefile([], 'Xtmpfile')
1281 silent e Xtmpfile
1282 var d = {[bufnr('%')]: {a: 0}}
1283 au BufReadPost * Func()
1284 def Func()
1285 if d->has_key('')
1286 endif
1287 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
1288 enddef
1289 e
1290 END
1291 CheckScriptFailure(lines, 'E1013:')
1292 au! BufReadPost
1293 delete('Xtmpfile')
1294enddef
1295
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001296def Test_matcharg()
1297 CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1298enddef
1299
1300def Test_matchdelete()
1301 CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1302 CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1303 CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1304enddef
1305
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001306def Test_max()
1307 g:flag = true
1308 var l1: list<number> = g:flag
1309 ? [1, max([2, 3])]
1310 : [4, 5]
1311 assert_equal([1, 3], l1)
1312
1313 g:flag = false
1314 var l2: list<number> = g:flag
1315 ? [1, max([2, 3])]
1316 : [4, 5]
1317 assert_equal([4, 5], l2)
1318enddef
1319
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001320def Test_menu_info()
1321 CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1322 CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1323 CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1324 assert_equal({}, menu_info('aMenu'))
1325enddef
1326
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001327def Test_min()
1328 g:flag = true
1329 var l1: list<number> = g:flag
1330 ? [1, min([2, 3])]
1331 : [4, 5]
1332 assert_equal([1, 2], l1)
1333
1334 g:flag = false
1335 var l2: list<number> = g:flag
1336 ? [1, min([2, 3])]
1337 : [4, 5]
1338 assert_equal([4, 5], l2)
1339enddef
1340
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001341def Test_nextnonblank()
1342 CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1343 assert_equal(0, nextnonblank(1))
1344enddef
1345
Bram Moolenaar94738d82020-10-21 14:25:07 +02001346def Test_nr2char()
1347 nr2char(97, true)->assert_equal('a')
1348enddef
1349
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001350def Test_or()
1351 CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1352 CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1353enddef
1354
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001355def Test_prevnonblank()
1356 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1357 assert_equal(0, prevnonblank(1))
1358enddef
1359
1360def Test_prompt_getprompt()
Dominique Pelle74509232021-07-03 19:27:37 +02001361 if has('channel')
1362 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1363 assert_equal('', prompt_getprompt('NonExistingBuf'))
1364 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001365enddef
1366
1367def Test_rand()
1368 CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number')
1369 CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1370 assert_true(rand() >= 0)
1371 assert_true(rand(srand()) >= 0)
1372enddef
1373
Bram Moolenaar94738d82020-10-21 14:25:07 +02001374def Test_readdir()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001375 eval expand('sautest')->readdir((e) => e[0] !=# '.')
1376 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001377enddef
1378
Bram Moolenaarc423ad72021-01-13 20:38:03 +01001379def Test_readblob()
1380 var blob = 0z12341234
1381 writefile(blob, 'Xreadblob')
1382 var read: blob = readblob('Xreadblob')
1383 assert_equal(blob, read)
1384
1385 var lines =<< trim END
1386 var read: list<string> = readblob('Xreadblob')
1387 END
1388 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
1389 delete('Xreadblob')
1390enddef
1391
1392def Test_readfile()
1393 var text = ['aaa', 'bbb', 'ccc']
1394 writefile(text, 'Xreadfile')
1395 var read: list<string> = readfile('Xreadfile')
1396 assert_equal(text, read)
1397
1398 var lines =<< trim END
1399 var read: dict<string> = readfile('Xreadfile')
1400 END
1401 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
1402 delete('Xreadfile')
1403enddef
1404
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001405def Test_reltime()
1406 CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
1407 CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1408 CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
1409 CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
1410 var start: list<any> = reltime()
1411 assert_true(type(reltime(start)) == v:t_list)
1412 var end: list<any> = reltime()
1413 assert_true(type(reltime(start, end)) == v:t_list)
1414enddef
1415
1416def Test_reltimefloat()
1417 CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
1418 CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
1419 assert_true(type(reltimefloat(reltime())) == v:t_float)
1420enddef
1421
1422def Test_reltimestr()
1423 CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
1424 CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
1425 assert_true(type(reltimestr(reltime())) == v:t_string)
1426enddef
1427
1428def Test_remote_foreground()
1429 CheckFeature clientserver
1430 # remote_foreground() doesn't fail on MS-Windows
1431 CheckNotMSWindows
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +02001432 CheckEnv DISPLAY
1433
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001434 CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1435 assert_fails('remote_foreground("NonExistingServer")', 'E241:')
1436enddef
1437
1438def Test_remote_startserver()
1439 CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1440enddef
1441
Bram Moolenaar94738d82020-10-21 14:25:07 +02001442def Test_remove_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001443 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001444 var res = 0
1445 for n in l
1446 res += n
1447 endfor
1448 res->assert_equal(3)
1449enddef
1450
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001451def Test_rename()
1452 CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1453 CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1454enddef
1455
1456def Test_resolve()
1457 CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1458 assert_equal('SomeFile', resolve('SomeFile'))
1459enddef
1460
Bram Moolenaar94738d82020-10-21 14:25:07 +02001461def Test_reverse_return_type()
1462 var l = reverse([1, 2, 3])
1463 var res = 0
1464 for n in l
1465 res += n
1466 endfor
1467 res->assert_equal(6)
1468enddef
1469
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001470def Test_screenattr()
1471 CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1472 CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1473enddef
1474
1475def Test_screenchar()
1476 CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1477 CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1478enddef
1479
1480def Test_screenchars()
1481 CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1482 CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1483enddef
1484
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001485def Test_screenpos()
1486 CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1487 CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string')
1488 CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string')
1489 assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1))
1490enddef
1491
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001492def Test_screenstring()
1493 CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1494 CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1495enddef
1496
Bram Moolenaar94738d82020-10-21 14:25:07 +02001497def Test_search()
1498 new
1499 setline(1, ['foo', 'bar'])
1500 var val = 0
1501 # skip expr returns boolean
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001502 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001503 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001504 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001505 # skip expr returns number, only 0 and 1 are accepted
1506 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001507 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001508 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001509 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
1510 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
1511 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001512
1513 setline(1, "find this word")
1514 normal gg
1515 var col = 7
1516 assert_equal(1, search('this', '', 0, 0, 'col(".") > col'))
1517 normal 0
1518 assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col'))
1519
1520 col = 5
1521 normal 0
1522 assert_equal(0, search('this', '', 0, 0, 'col(".") > col'))
1523 normal 0
1524 assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col'))
1525 bwipe!
Bram Moolenaar94738d82020-10-21 14:25:07 +02001526enddef
1527
1528def Test_searchcount()
1529 new
1530 setline(1, "foo bar")
1531 :/foo
Bram Moolenaare0de1712020-12-02 17:36:54 +01001532 searchcount({recompute: true})
1533 ->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001534 exact_match: 1,
1535 current: 1,
1536 total: 1,
1537 maxcount: 99,
1538 incomplete: 0})
1539 bwipe!
1540enddef
1541
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001542def Test_searchpair()
1543 new
1544 setline(1, "here { and } there")
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001545
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001546 normal f{
1547 var col = 15
1548 assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col'))
1549 assert_equal(12, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001550 normal 0f{
1551 assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col'))
1552
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001553 col = 8
1554 normal 0f{
1555 assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col'))
1556 assert_equal(6, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02001557 normal 0f{
1558 assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col'))
1559
Bram Moolenaarff652882021-05-16 15:24:49 +02001560 var lines =<< trim END
1561 vim9script
1562 setline(1, '()')
1563 normal gg
1564 def Fail()
1565 try
1566 searchpairpos('(', '', ')', 'nW', '[0]->map("")')
1567 catch
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001568 g:caught = 'yes'
Bram Moolenaarff652882021-05-16 15:24:49 +02001569 endtry
1570 enddef
1571 Fail()
1572 END
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001573 CheckScriptSuccess(lines)
1574 assert_equal('yes', g:caught)
Bram Moolenaarff652882021-05-16 15:24:49 +02001575
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02001576 unlet g:caught
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001577 bwipe!
1578enddef
1579
Bram Moolenaar34453202021-01-31 13:08:38 +01001580def Test_set_get_bufline()
1581 # similar to Test_setbufline_getbufline()
1582 var lines =<< trim END
1583 new
1584 var b = bufnr('%')
1585 hide
1586 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
1587 assert_equal(['foo'], getbufline(b, 1))
1588 assert_equal(['bar'], getbufline(b, '$'))
1589 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
1590 exe "bd!" b
1591 assert_equal([], getbufline(b, 1, 2))
1592
1593 split Xtest
1594 setline(1, ['a', 'b', 'c'])
1595 b = bufnr('%')
1596 wincmd w
1597
1598 assert_equal(1, setbufline(b, 5, 'x'))
1599 assert_equal(1, setbufline(b, 5, ['x']))
1600 assert_equal(1, setbufline(b, 5, []))
1601 assert_equal(1, setbufline(b, 5, test_null_list()))
1602
1603 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
1604 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
1605 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
1606 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
1607
1608 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
1609
1610 assert_equal(0, setbufline(b, 4, ['d', 'e']))
1611 assert_equal(['c'], b->getbufline(3))
1612 assert_equal(['d'], getbufline(b, 4))
1613 assert_equal(['e'], getbufline(b, 5))
1614 assert_equal([], getbufline(b, 6))
1615 assert_equal([], getbufline(b, 2, 1))
1616
Bram Moolenaar00385112021-02-07 14:31:06 +01001617 if has('job')
Bram Moolenaar1328bde2021-06-05 20:51:38 +02001618 setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())])
Bram Moolenaar00385112021-02-07 14:31:06 +01001619 assert_equal(["function('eval')",
1620 "{'key': 123}",
1621 "no process"],
1622 getbufline(b, 2, 4))
1623 endif
Bram Moolenaar34453202021-01-31 13:08:38 +01001624
1625 exe 'bwipe! ' .. b
1626 END
1627 CheckDefAndScriptSuccess(lines)
1628enddef
1629
Bram Moolenaar94738d82020-10-21 14:25:07 +02001630def Test_searchdecl()
1631 searchdecl('blah', true, true)->assert_equal(1)
1632enddef
1633
1634def Test_setbufvar()
1635 setbufvar(bufnr('%'), '&syntax', 'vim')
1636 &syntax->assert_equal('vim')
1637 setbufvar(bufnr('%'), '&ts', 16)
1638 &ts->assert_equal(16)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01001639 setbufvar(bufnr('%'), '&ai', true)
1640 &ai->assert_equal(true)
1641 setbufvar(bufnr('%'), '&ft', 'filetype')
1642 &ft->assert_equal('filetype')
1643
Bram Moolenaar94738d82020-10-21 14:25:07 +02001644 settabwinvar(1, 1, '&syntax', 'vam')
1645 &syntax->assert_equal('vam')
1646 settabwinvar(1, 1, '&ts', 15)
1647 &ts->assert_equal(15)
1648 setlocal ts=8
Bram Moolenaarb0d81822021-01-03 15:55:10 +01001649 settabwinvar(1, 1, '&list', false)
1650 &list->assert_equal(false)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01001651 settabwinvar(1, 1, '&list', true)
1652 &list->assert_equal(true)
1653 setlocal list&
Bram Moolenaar94738d82020-10-21 14:25:07 +02001654
1655 setbufvar('%', 'myvar', 123)
1656 getbufvar('%', 'myvar')->assert_equal(123)
1657enddef
1658
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001659def Test_setcharsearch()
1660 CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
1661 CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1662 var d: dict<any> = {char: 'x', forward: 1, until: 1}
1663 setcharsearch(d)
1664 assert_equal(d, getcharsearch())
1665enddef
1666
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001667def Test_setcmdpos()
1668 CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1669enddef
1670
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001671def Test_setfperm()
1672 CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1673 CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
1674enddef
1675
Bram Moolenaar94738d82020-10-21 14:25:07 +02001676def Test_setloclist()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001677 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
1678 var what = {items: items}
Bram Moolenaar94738d82020-10-21 14:25:07 +02001679 setqflist([], ' ', what)
1680 setloclist(0, [], ' ', what)
1681enddef
1682
1683def Test_setreg()
1684 setreg('a', ['aaa', 'bbb', 'ccc'])
1685 var reginfo = getreginfo('a')
1686 setreg('a', reginfo)
1687 getreginfo('a')->assert_equal(reginfo)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001688 assert_fails('setreg("ab", 0)', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001689enddef
1690
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001691def Test_sha256()
1692 CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1693 CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
1694 assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc'))
1695enddef
1696
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001697def Test_shiftwidth()
1698 CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1699enddef
1700
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001701def Test_simplify()
1702 CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1703 call assert_equal('NonExistingFile', simplify('NonExistingFile'))
1704enddef
1705
Bram Moolenaar6601b622021-01-13 21:47:15 +01001706def Test_slice()
1707 assert_equal('12345', slice('012345', 1))
1708 assert_equal('123', slice('012345', 1, 4))
1709 assert_equal('1234', slice('012345', 1, -1))
1710 assert_equal('1', slice('012345', 1, -4))
1711 assert_equal('', slice('012345', 1, -5))
1712 assert_equal('', slice('012345', 1, -6))
1713
1714 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
1715 assert_equal([1, 2, 3], slice(range(6), 1, 4))
1716 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
1717 assert_equal([1], slice(range(6), 1, -4))
1718 assert_equal([], slice(range(6), 1, -5))
1719 assert_equal([], slice(range(6), 1, -6))
1720
1721 assert_equal(0z1122334455, slice(0z001122334455, 1))
1722 assert_equal(0z112233, slice(0z001122334455, 1, 4))
1723 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
1724 assert_equal(0z11, slice(0z001122334455, 1, -4))
1725 assert_equal(0z, slice(0z001122334455, 1, -5))
1726 assert_equal(0z, slice(0z001122334455, 1, -6))
1727enddef
1728
Bram Moolenaar94738d82020-10-21 14:25:07 +02001729def Test_spellsuggest()
1730 if !has('spell')
1731 MissingFeature 'spell'
1732 else
1733 spellsuggest('marrch', 1, true)->assert_equal(['March'])
1734 endif
1735enddef
1736
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001737def Test_sound_stop()
1738 CheckFeature sound
1739 CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1740enddef
1741
1742def Test_soundfold()
1743 CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1744 assert_equal('abc', soundfold('abc'))
1745enddef
1746
Bram Moolenaar94738d82020-10-21 14:25:07 +02001747def Test_sort_return_type()
1748 var res: list<number>
1749 res = [1, 2, 3]->sort()
1750enddef
1751
1752def Test_sort_argument()
Bram Moolenaar08cf0c02020-12-05 21:47:06 +01001753 var lines =<< trim END
1754 var res = ['b', 'a', 'c']->sort('i')
1755 res->assert_equal(['a', 'b', 'c'])
1756
1757 def Compare(a: number, b: number): number
1758 return a - b
1759 enddef
1760 var l = [3, 6, 7, 1, 8, 2, 4, 5]
1761 sort(l, Compare)
1762 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
1763 END
1764 CheckDefAndScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001765enddef
1766
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001767def Test_spellbadword()
1768 CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1769 spellbadword('good')->assert_equal(['', ''])
1770enddef
1771
Bram Moolenaar94738d82020-10-21 14:25:07 +02001772def Test_split()
1773 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
1774enddef
1775
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001776def Test_srand()
1777 CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1778 type(srand(100))->assert_equal(v:t_list)
1779enddef
1780
1781def Test_state()
1782 CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1783 assert_equal('', state('a'))
1784enddef
1785
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01001786def Run_str2float()
1787 if !has('float')
1788 MissingFeature 'float'
1789 endif
1790 str2float("1.00")->assert_equal(1.00)
1791 str2float("2e-2")->assert_equal(0.02)
1792
1793 CheckDefFailure(['echo str2float(123)'], 'E1013:')
1794 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
1795 endif
1796enddef
1797
Bram Moolenaar94738d82020-10-21 14:25:07 +02001798def Test_str2nr()
1799 str2nr("1'000'000", 10, true)->assert_equal(1000000)
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01001800
1801 CheckDefFailure(['echo str2nr(123)'], 'E1013:')
1802 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
1803 CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:')
1804 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
1805 CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:')
1806 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001807enddef
1808
1809def Test_strchars()
1810 strchars("A\u20dd", true)->assert_equal(1)
1811enddef
1812
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001813def Test_strlen()
1814 CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1815 "abc"->strlen()->assert_equal(3)
1816 strlen(99)->assert_equal(2)
1817enddef
1818
1819def Test_strptime()
1820 CheckFunction strptime
1821 CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1822 CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1823 # BUG: Directly calling strptime() in this function gives an "E117: Unknown
1824 # function" error on MS-Windows even with the above CheckFunction call for
1825 # strptime().
1826 #assert_true(strptime('%Y', '2021') != 0)
1827enddef
1828
1829def Test_strtrans()
1830 CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1831 assert_equal('abc', strtrans('abc'))
1832enddef
1833
1834def Test_strwidth()
1835 CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1836 CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:')
1837 assert_equal(4, strwidth('abcd'))
1838enddef
1839
Bram Moolenaar94738d82020-10-21 14:25:07 +02001840def Test_submatch()
1841 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
Bram Moolenaar75ab91f2021-01-10 22:42:50 +01001842 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001843 var actual = substitute('A123456789', pat, Rep, '')
1844 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
1845 actual->assert_equal(expected)
1846enddef
1847
Bram Moolenaar1328bde2021-06-05 20:51:38 +02001848def Test_substitute()
1849 var res = substitute('A1234', '\d', 'X', '')
1850 assert_equal('AX234', res)
1851
1852 if has('job')
1853 assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job')
1854 assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel')
1855 endif
1856enddef
1857
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001858def Test_swapinfo()
1859 CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1860 call assert_equal({error: 'Cannot open file'}, swapinfo('x'))
1861enddef
1862
1863def Test_swapname()
1864 CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1865 assert_fails('swapname("NonExistingBuf")', 'E94:')
1866enddef
1867
Bram Moolenaar94738d82020-10-21 14:25:07 +02001868def Test_synID()
1869 new
1870 setline(1, "text")
1871 synID(1, 1, true)->assert_equal(0)
1872 bwipe!
1873enddef
1874
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001875def Test_synIDtrans()
1876 CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1877enddef
1878
1879def Test_tabpagebuflist()
1880 CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1881 assert_equal([bufnr('')], tabpagebuflist())
1882 assert_equal([bufnr('')], tabpagebuflist(1))
1883enddef
1884
1885def Test_tabpagenr()
1886 CheckDefFailure(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1887 assert_equal(1, tabpagenr('$'))
1888 assert_equal(1, tabpagenr())
1889enddef
1890
Bram Moolenaar94738d82020-10-21 14:25:07 +02001891def Test_term_gettty()
1892 if !has('terminal')
1893 MissingFeature 'terminal'
1894 else
1895 var buf = Run_shell_in_terminal({})
1896 term_gettty(buf, true)->assert_notequal('')
1897 StopShellInTerminal(buf)
1898 endif
1899enddef
1900
1901def Test_term_start()
1902 if !has('terminal')
1903 MissingFeature 'terminal'
1904 else
1905 botright new
1906 var winnr = winnr()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001907 term_start(&shell, {curwin: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001908 winnr()->assert_equal(winnr)
1909 bwipe!
1910 endif
1911enddef
1912
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001913def Test_timer_info()
1914 CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1915 assert_equal([], timer_info(100))
1916 assert_equal([], timer_info())
1917enddef
1918
Bram Moolenaar94738d82020-10-21 14:25:07 +02001919def Test_timer_paused()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001920 var id = timer_start(50, () => 0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001921 timer_pause(id, true)
1922 var info = timer_info(id)
1923 info[0]['paused']->assert_equal(1)
1924 timer_stop(id)
1925enddef
1926
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001927def Test_timer_stop()
1928 CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1929 assert_equal(0, timer_stop(100))
1930enddef
1931
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001932def Test_tolower()
1933 CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1934enddef
1935
1936def Test_toupper()
1937 CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1938enddef
1939
1940def Test_tr()
1941 CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1942 CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1943 CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1944enddef
1945
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001946def Test_undofile()
1947 CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1948 assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t'))
1949enddef
1950
1951def Test_values()
1952 CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1953 assert_equal([], {}->values())
1954 assert_equal(['sun'], {star: 'sun'}->values())
1955enddef
1956
Bram Moolenaar37487e12021-01-12 22:08:53 +01001957def Test_win_execute()
1958 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
1959 assert_equal('', win_execute(342343, 'echo winnr()'))
1960enddef
1961
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001962def Test_win_findbuf()
1963 CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1964 assert_equal([], win_findbuf(1000))
1965 assert_equal([win_getid()], win_findbuf(bufnr('')))
1966enddef
1967
1968def Test_win_getid()
1969 CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1970 CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1971 assert_equal(win_getid(), win_getid(1, 1))
1972enddef
1973
Bram Moolenaar94738d82020-10-21 14:25:07 +02001974def Test_win_splitmove()
1975 split
Bram Moolenaare0de1712020-12-02 17:36:54 +01001976 win_splitmove(1, 2, {vertical: true, rightbelow: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001977 close
1978enddef
1979
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001980def Test_winnr()
1981 CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1982 assert_equal(1, winnr())
1983 assert_equal(1, winnr('$'))
1984enddef
1985
Bram Moolenaar285b15f2020-12-29 20:25:19 +01001986def Test_winrestcmd()
1987 split
1988 var cmd = winrestcmd()
1989 wincmd _
1990 exe cmd
1991 assert_equal(cmd, winrestcmd())
1992 close
1993enddef
1994
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001995def Test_winrestview()
1996 CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1997 :%d _
1998 setline(1, 'Hello World')
1999 winrestview({lnum: 1, col: 6})
2000 assert_equal([1, 7], [line('.'), col('.')])
2001enddef
2002
Bram Moolenaar43b69b32021-01-07 20:23:33 +01002003def Test_winsaveview()
2004 var view: dict<number> = winsaveview()
2005
2006 var lines =<< trim END
2007 var view: list<number> = winsaveview()
2008 END
2009 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
2010enddef
2011
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002012def Test_win_gettype()
2013 CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2014enddef
Bram Moolenaar43b69b32021-01-07 20:23:33 +01002015
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002016def Test_win_gotoid()
2017 CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2018enddef
Bram Moolenaar285b15f2020-12-29 20:25:19 +01002019
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002020def Test_win_id2tabwin()
2021 CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2022enddef
2023
2024def Test_win_id2win()
2025 CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2026enddef
2027
2028def Test_win_screenpos()
2029 CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2030enddef
2031
2032def Test_winbufnr()
2033 CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2034enddef
2035
2036def Test_winheight()
2037 CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2038enddef
2039
2040def Test_winlayout()
2041 CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2042enddef
2043
2044def Test_winwidth()
2045 CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2046enddef
2047
2048def Test_xor()
2049 CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2050 CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
2051enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02002052
2053" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker