blob: b994855b8cb69cb9fa4d0f06b6e14cb99b9f939d [file] [log] [blame]
Bram Moolenaar62aec932022-01-29 21:45:34 +00001vim9script
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02002
Hirohito Higashifbe4a8f2025-04-27 15:28:30 +02003# Utility functions for testing Vim9 script
Bram Moolenaar2d870f82020-12-05 13:41:01 +01004
Bram Moolenaar62aec932022-01-29 21:45:34 +00005# Use a different file name for each run.
6var sequence = 1
7
8# Check that "lines" inside a ":def" function has no error when called.
9export func CheckDefSuccess(lines)
Bram Moolenaar090728a2020-12-20 15:43:31 +010010 let cwd = getcwd()
11 let fname = 'XdefSuccess' .. s:sequence
Bram Moolenaar2d870f82020-12-05 13:41:01 +010012 let s:sequence += 1
13 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
Bram Moolenaar090728a2020-12-20 15:43:31 +010014 try
15 exe 'so ' .. fname
16 call Func()
Bram Moolenaar090728a2020-12-20 15:43:31 +010017 finally
18 call chdir(cwd)
19 call delete(fname)
Bram Moolenaar88c89c72021-08-14 14:01:05 +020020 delfunc! Func
Bram Moolenaar090728a2020-12-20 15:43:31 +010021 endtry
Bram Moolenaar3e06a1e2020-08-10 21:57:54 +020022endfunc
23
Bram Moolenaar62aec932022-01-29 21:45:34 +000024# Check that "lines" inside a ":def" function has no error when compiled.
25export func CheckDefCompileSuccess(lines)
Bram Moolenaar08018222021-12-22 18:45:37 +000026 let fname = 'XdefSuccess' .. s:sequence
27 let s:sequence += 1
28 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
29 try
30 exe 'so ' .. fname
31 finally
32 call delete(fname)
33 delfunc! Func
34 endtry
35endfunc
36
Bram Moolenaar62aec932022-01-29 21:45:34 +000037# Check that "lines" inside ":def" results in an "error" message.
38# If "lnum" is given check that the error is reported for this line.
39# Add a line before and after to make it less likely that the line number is
40# accidentally correct.
41export func CheckDefFailure(lines, error, lnum = -3)
Bram Moolenaar090728a2020-12-20 15:43:31 +010042 let cwd = getcwd()
43 let fname = 'XdefFailure' .. s:sequence
Bram Moolenaar2d870f82020-12-05 13:41:01 +010044 let s:sequence += 1
Bram Moolenaar090728a2020-12-20 15:43:31 +010045 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
46 try
47 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
48 finally
49 call chdir(cwd)
50 call delete(fname)
51 delfunc! Func
52 endtry
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020053endfunc
54
Bram Moolenaar62aec932022-01-29 21:45:34 +000055# Check that "lines" inside ":def" results in an "error" message when executed.
56# If "lnum" is given check that the error is reported for this line.
57# Add a line before and after to make it less likely that the line number is
58# accidentally correct.
59export func CheckDefExecFailure(lines, error, lnum = -3)
Bram Moolenaar090728a2020-12-20 15:43:31 +010060 let cwd = getcwd()
61 let fname = 'XdefExecFailure' .. s:sequence
Bram Moolenaar2d870f82020-12-05 13:41:01 +010062 let s:sequence += 1
63 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
Bram Moolenaar090728a2020-12-20 15:43:31 +010064 try
65 exe 'so ' .. fname
66 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
67 finally
68 call chdir(cwd)
69 call delete(fname)
70 delfunc! Func
71 endtry
Bram Moolenaar015f4262020-05-05 21:25:22 +020072endfunc
73
Bram Moolenaar62aec932022-01-29 21:45:34 +000074export def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
Bram Moolenaar090728a2020-12-20 15:43:31 +010075 var cwd = getcwd()
Bram Moolenaara749a422022-02-12 19:52:25 +000076 var fname = 'XScriptFailure' .. sequence
77 sequence += 1
Bram Moolenaar2d870f82020-12-05 13:41:01 +010078 writefile(lines, fname)
Bram Moolenaar090728a2020-12-20 15:43:31 +010079 try
80 assert_fails('so ' .. fname, error, lines, lnum)
81 finally
82 chdir(cwd)
83 delete(fname)
84 endtry
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020085enddef
86
Bram Moolenaar62aec932022-01-29 21:45:34 +000087export def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
Bram Moolenaarc5f59fa2021-01-21 12:34:14 +010088 var cwd = getcwd()
Bram Moolenaara749a422022-02-12 19:52:25 +000089 var fname = 'XScriptFailure' .. sequence
90 sequence += 1
Bram Moolenaarc5f59fa2021-01-21 12:34:14 +010091 writefile(lines, fname)
92 try
93 assert_fails('so ' .. fname, errors, lines, lnum)
94 finally
95 chdir(cwd)
96 delete(fname)
97 endtry
98enddef
99
Bram Moolenaar62aec932022-01-29 21:45:34 +0000100export def CheckScriptSuccess(lines: list<string>)
Bram Moolenaar090728a2020-12-20 15:43:31 +0100101 var cwd = getcwd()
Bram Moolenaara749a422022-02-12 19:52:25 +0000102 var fname = 'XScriptSuccess' .. sequence
103 sequence += 1
Bram Moolenaar2d870f82020-12-05 13:41:01 +0100104 writefile(lines, fname)
Bram Moolenaar090728a2020-12-20 15:43:31 +0100105 try
106 exe 'so ' .. fname
107 finally
108 chdir(cwd)
109 delete(fname)
110 endtry
Bram Moolenaarcfe435d2020-04-25 20:02:55 +0200111enddef
Bram Moolenaar7cb6fc22020-08-21 22:36:47 +0200112
Bram Moolenaar62aec932022-01-29 21:45:34 +0000113export def CheckDefAndScriptSuccess(lines: list<string>)
Bram Moolenaar2e800952020-08-23 19:34:48 +0200114 CheckDefSuccess(lines)
115 CheckScriptSuccess(['vim9script'] + lines)
116enddef
117
Bram Moolenaar62aec932022-01-29 21:45:34 +0000118# Check that a command fails when used in a :def function and when used in
119# Vim9 script.
120# When "error" is a string, both with the same error.
121# When "error" is a list, the :def function fails with "error[0]" , the script
122# fails with "error[1]".
123export def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
Bram Moolenaar86b3ab42021-12-19 18:33:23 +0000124 var errorDef: string
125 var errorScript: string
126 if type(error) == v:t_string
127 errorDef = error
128 errorScript = error
129 elseif type(error) == v:t_list && len(error) == 2
130 errorDef = error[0]
131 errorScript = error[1]
132 else
133 echoerr 'error argument must be a string or a list with two items'
134 return
135 endif
Bram Moolenaar90193e62021-04-04 20:49:50 +0200136 CheckDefFailure(lines, errorDef, lnum)
137 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
138enddef
139
Bram Moolenaar62aec932022-01-29 21:45:34 +0000140# Check that a command fails when executed in a :def function and when used in
141# Vim9 script.
142# When "error" is a string, both with the same error.
143# When "error" is a list, the :def function fails with "error[0]" , the script
144# fails with "error[1]".
145export def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
Bram Moolenaar86b3ab42021-12-19 18:33:23 +0000146 var errorDef: string
147 var errorScript: string
148 if type(error) == v:t_string
149 errorDef = error
150 errorScript = error
151 elseif type(error) == v:t_list && len(error) == 2
152 errorDef = error[0]
153 errorScript = error[1]
154 else
155 echoerr 'error argument must be a string or a list with two items'
156 return
157 endif
Bram Moolenaar90193e62021-04-04 20:49:50 +0200158 CheckDefExecFailure(lines, errorDef, lnum)
159 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
160enddef
Bram Moolenaar68452172021-04-12 21:21:02 +0200161
162
Bram Moolenaar62aec932022-01-29 21:45:34 +0000163# Check that "lines" inside a legacy function has no error.
164export func CheckLegacySuccess(lines)
Bram Moolenaar68452172021-04-12 21:21:02 +0200165 let cwd = getcwd()
166 let fname = 'XlegacySuccess' .. s:sequence
167 let s:sequence += 1
168 call writefile(['func Func()'] + a:lines + ['endfunc'], fname)
169 try
170 exe 'so ' .. fname
171 call Func()
Bram Moolenaar68452172021-04-12 21:21:02 +0200172 finally
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200173 delfunc! Func
174 call chdir(cwd)
175 call delete(fname)
176 endtry
177endfunc
178
Bram Moolenaar62aec932022-01-29 21:45:34 +0000179# Check that "lines" inside a legacy function results in the expected error
180export func CheckLegacyFailure(lines, error)
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200181 let cwd = getcwd()
182 let fname = 'XlegacyFails' .. s:sequence
183 let s:sequence += 1
184 call writefile(['func Func()'] + a:lines + ['endfunc', 'call Func()'], fname)
185 try
186 call assert_fails('so ' .. fname, a:error)
187 finally
188 delfunc! Func
Bram Moolenaar68452172021-04-12 21:21:02 +0200189 call chdir(cwd)
190 call delete(fname)
191 endtry
192endfunc
193
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100194# Translate "lines" to legacy Vim script
195def LegacyTrans(lines: list<string>): list<string>
196 return lines->mapnew((_, v) =>
197 v->substitute('\<VAR\>', 'let', 'g')
198 ->substitute('\<LET\>', 'let', 'g')
199 ->substitute('\<LSTART\>', '{', 'g')
200 ->substitute('\<LMIDDLE\>', '->', 'g')
201 ->substitute('\<LEND\>', '}', 'g')
202 ->substitute('\<TRUE\>', '1', 'g')
203 ->substitute('\<FALSE\>', '0', 'g')
204 ->substitute('#"', ' "', 'g'))
205enddef
206
Bram Moolenaar62aec932022-01-29 21:45:34 +0000207# Execute "lines" in a legacy function, translated as in
208# CheckLegacyAndVim9Success()
209export def CheckTransLegacySuccess(lines: list<string>)
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100210 CheckLegacySuccess(LegacyTrans(lines))
Bram Moolenaar3e9c0b92021-08-12 10:39:10 +0200211enddef
Bram Moolenaar68452172021-04-12 21:21:02 +0200212
Bram Moolenaar62aec932022-01-29 21:45:34 +0000213export def Vim9Trans(lines: list<string>): list<string>
Bram Moolenaarfea43e42021-12-19 21:34:05 +0000214 return lines->mapnew((_, v) =>
215 v->substitute('\<VAR\>', 'var', 'g')
216 ->substitute('\<LET ', '', 'g')
217 ->substitute('\<LSTART\>', '(', 'g')
218 ->substitute('\<LMIDDLE\>', ') =>', 'g')
219 ->substitute(' *\<LEND\> *', '', 'g')
220 ->substitute('\<TRUE\>', 'true', 'g')
221 ->substitute('\<FALSE\>', 'false', 'g'))
222enddef
223
Bram Moolenaar62aec932022-01-29 21:45:34 +0000224# Execute "lines" in a :def function, translated as in
225# CheckLegacyAndVim9Success()
226export def CheckTransDefSuccess(lines: list<string>)
Bram Moolenaarfea43e42021-12-19 21:34:05 +0000227 CheckDefSuccess(Vim9Trans(lines))
Bram Moolenaar3e9c0b92021-08-12 10:39:10 +0200228enddef
229
Bram Moolenaar62aec932022-01-29 21:45:34 +0000230# Execute "lines" in a Vim9 script, translated as in
231# CheckLegacyAndVim9Success()
232export def CheckTransVim9Success(lines: list<string>)
Bram Moolenaarfea43e42021-12-19 21:34:05 +0000233 CheckScriptSuccess(['vim9script'] + Vim9Trans(lines))
Bram Moolenaar68452172021-04-12 21:21:02 +0200234enddef
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200235
Bram Moolenaar62aec932022-01-29 21:45:34 +0000236# Execute "lines" in a legacy function, :def function and Vim9 script.
237# Use 'VAR' for a declaration.
238# Use 'LET' for an assignment
239# Use ' #"' for a comment
240# Use LSTART arg LMIDDLE expr LEND for lambda
241# Use 'TRUE' for 1 in legacy, true in Vim9
242# Use 'FALSE' for 0 in legacy, false in Vim9
243export def CheckLegacyAndVim9Success(lines: list<string>)
Bram Moolenaar3e9c0b92021-08-12 10:39:10 +0200244 CheckTransLegacySuccess(lines)
245 CheckTransDefSuccess(lines)
246 CheckTransVim9Success(lines)
247enddef
248
Bram Moolenaar62aec932022-01-29 21:45:34 +0000249# Execute "lines" in a legacy function, :def function and Vim9 script.
250# Use 'VAR' for a declaration.
251# Use 'LET' for an assignment
252# Use ' #"' for a comment
253export def CheckLegacyAndVim9Failure(lines: list<string>, error: any)
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200254 var legacyError: string
255 var defError: string
256 var scriptError: string
257
258 if type(error) == type('string')
259 legacyError = error
260 defError = error
261 scriptError = error
262 else
263 legacyError = error[0]
264 defError = error[1]
265 scriptError = error[2]
266 endif
267
268 var legacylines = lines->mapnew((_, v) =>
Bram Moolenaar94722c52023-01-28 19:19:03 +0000269 v->substitute('\<VAR\>', 'let', 'g')
270 ->substitute('\<LET\>', 'let', 'g')
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100271 ->substitute('\<LSTART\>', '{', 'g')
272 ->substitute('\<LMIDDLE\>', '->', 'g')
273 ->substitute('\<LEND\>', '}', 'g')
274 ->substitute('\<TRUE\>', '1', 'g')
275 ->substitute('\<FALSE\>', '0', 'g')
Bram Moolenaar94722c52023-01-28 19:19:03 +0000276 ->substitute('#"', ' "', 'g'))
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200277 CheckLegacyFailure(legacylines, legacyError)
278
279 var vim9lines = lines->mapnew((_, v) =>
Bram Moolenaar94722c52023-01-28 19:19:03 +0000280 v->substitute('\<VAR\>', 'var', 'g')
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100281 ->substitute('\<LET ', '', 'g')
282 ->substitute('\<LSTART\>', '(', 'g')
283 ->substitute('\<LMIDDLE\>', ') =>', 'g')
284 ->substitute(' *\<LEND\> *', '', 'g')
285 ->substitute('\<TRUE\>', 'true', 'g')
286 ->substitute('\<FALSE\>', 'false', 'g'))
Bram Moolenaar0e3ff192021-04-14 20:35:23 +0200287 CheckDefExecFailure(vim9lines, defError)
288 CheckScriptFailure(['vim9script'] + vim9lines, scriptError)
289enddef
Yegappan Lakshmanan22697b62024-04-22 20:58:24 +0200290
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100291# Check that "lines" inside a legacy function has no error.
292export func CheckSourceLegacySuccess(lines)
293 let cwd = getcwd()
294 new
295 call setline(1, ['func Func()'] + a:lines + ['endfunc', 'call Func()'])
296 let bnr = bufnr()
297 try
298 :source
299 finally
300 delfunc! Func
301 call chdir(cwd)
302 exe $':bw! {bnr}'
303 endtry
304endfunc
305
306# Check that "lines" inside a legacy function results in the expected error
307export func CheckSourceLegacyFailure(lines, error)
308 let cwd = getcwd()
309 new
310 call setline(1, ['func Func()'] + a:lines + ['endfunc', 'call Func()'])
311 let bnr = bufnr()
312 try
313 call assert_fails('source', a:error)
314 finally
315 delfunc! Func
316 call chdir(cwd)
317 exe $':bw! {bnr}'
318 endtry
319endfunc
320
321# Execute "lines" in a legacy function, translated as in
322# CheckSourceLegacyAndVim9Success()
323export def CheckSourceTransLegacySuccess(lines: list<string>)
324 CheckSourceLegacySuccess(LegacyTrans(lines))
325enddef
326
327# Execute "lines" in a :def function, translated as in
328# CheckLegacyAndVim9Success()
329export def CheckSourceTransDefSuccess(lines: list<string>)
330 CheckSourceDefSuccess(Vim9Trans(lines))
331enddef
332
333# Execute "lines" in a Vim9 script, translated as in
334# CheckLegacyAndVim9Success()
335export def CheckSourceTransVim9Success(lines: list<string>)
336 CheckSourceScriptSuccess(['vim9script'] + Vim9Trans(lines))
337enddef
338
339# Execute "lines" in a legacy function, :def function and Vim9 script.
340# Use 'VAR' for a declaration.
341# Use 'LET' for an assignment
342# Use ' #"' for a comment
343# Use LSTART arg LMIDDLE expr LEND for lambda
344# Use 'TRUE' for 1 in legacy, true in Vim9
345# Use 'FALSE' for 0 in legacy, false in Vim9
346export def CheckSourceLegacyAndVim9Success(lines: list<string>)
347 CheckSourceTransLegacySuccess(lines)
348 CheckSourceTransDefSuccess(lines)
349 CheckSourceTransVim9Success(lines)
350enddef
351
Yegappan Lakshmanan22697b62024-04-22 20:58:24 +0200352# :source a list of "lines" and check whether it fails with "error"
353export def CheckSourceScriptFailure(lines: list<string>, error: string, lnum = -3)
354 var cwd = getcwd()
355 new
356 setline(1, lines)
357 var bnr = bufnr()
358 try
359 assert_fails('source', error, lines, lnum)
360 finally
361 chdir(cwd)
362 exe $':bw! {bnr}'
363 endtry
364enddef
365
366# :source a list of "lines" and check whether it fails with the list of
367# "errors"
368export def CheckSourceScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
369 var cwd = getcwd()
370 new
371 var bnr = bufnr()
372 setline(1, lines)
373 try
374 assert_fails('source', errors, lines, lnum)
375 finally
376 chdir(cwd)
377 exe $':bw! {bnr}'
378 endtry
379enddef
380
381# :source a list of "lines" and check whether it succeeds
382export def CheckSourceScriptSuccess(lines: list<string>)
383 var cwd = getcwd()
384 new
385 var bnr = bufnr()
386 setline(1, lines)
387 try
388 :source
389 finally
390 chdir(cwd)
391 exe $':bw! {bnr}'
392 endtry
393enddef
394
Yegappan Lakshmanan22697b62024-04-22 20:58:24 +0200395# :source a List of "lines" inside a ":def" function and check that no error
396# occurs when called.
397export func CheckSourceDefSuccess(lines)
398 let cwd = getcwd()
399 new
400 let bnr = bufnr()
401 call setline(1, ['def Func()'] + a:lines + ['enddef', 'defcompile'])
402 try
403 source
404 call Func()
405 finally
406 call chdir(cwd)
407 delfunc! Func
408 exe $'bw! {bnr}'
409 endtry
410endfunc
411
Yegappan Lakshmanan22697b62024-04-22 20:58:24 +0200412# Check that "lines" inside a ":def" function has no error when compiled.
413export func CheckSourceDefCompileSuccess(lines)
414 let cwd = getcwd()
415 new
416 let bnr = bufnr()
417 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'])
418 try
419 source
420 finally
421 call chdir(cwd)
422 delfunc! Func
423 exe $':bw! {bnr}'
424 endtry
425endfunc
426
427# Check that "lines" inside ":def" results in an "error" message.
428# If "lnum" is given check that the error is reported for this line.
429# Add a line before and after to make it less likely that the line number is
430# accidentally correct.
431export func CheckSourceDefFailure(lines, error, lnum = -3)
432 let cwd = getcwd()
433 new
434 let bnr = bufnr()
435 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'])
436 try
437 call assert_fails('source', a:error, a:lines, a:lnum + 1)
438 finally
439 call chdir(cwd)
440 delfunc! Func
441 exe $':bw! {bnr}'
442 endtry
443endfunc
444
445# Check that "lines" inside ":def" results in an "error" message when executed.
446# If "lnum" is given check that the error is reported for this line.
447# Add a line before and after to make it less likely that the line number is
448# accidentally correct.
449export func CheckSourceDefExecFailure(lines, error, lnum = -3)
450 let cwd = getcwd()
451 new
452 let bnr = bufnr()
453 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'])
454 try
455 source
456 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
457 finally
458 call chdir(cwd)
459 delfunc! Func
460 exe $':bw! {bnr}'
461 endtry
462endfunc
463
464# Check that a command fails when used in a :def function and when used in
465# Vim9 script.
466# When "error" is a string, both with the same error.
467# When "error" is a list, the :def function fails with "error[0]" , the script
468# fails with "error[1]".
469export def CheckSourceDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
470 var errorDef: string
471 var errorScript: string
472 if type(error) == v:t_string
473 errorDef = error
474 errorScript = error
475 elseif type(error) == v:t_list && len(error) == 2
476 errorDef = error[0]
477 errorScript = error[1]
478 else
479 echoerr 'error argument must be a string or a list with two items'
480 return
481 endif
482 CheckSourceDefFailure(lines, errorDef, lnum)
483 CheckSourceScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
484enddef
485
486# Check that a command fails when executed in a :def function and when used in
487# Vim9 script.
488# When "error" is a string, both with the same error.
489# When "error" is a list, the :def function fails with "error[0]" , the script
490# fails with "error[1]".
491export def CheckSourceDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
492 var errorDef: string
493 var errorScript: string
494 if type(error) == v:t_string
495 errorDef = error
496 errorScript = error
497 elseif type(error) == v:t_list && len(error) == 2
498 errorDef = error[0]
499 errorScript = error[1]
500 else
501 echoerr 'error argument must be a string or a list with two items'
502 return
503 endif
504 CheckSourceDefExecFailure(lines, errorDef, lnum)
505 CheckSourceScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
506enddef
507
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100508export def CheckSourceSuccess(lines: list<string>)
509 CheckSourceScriptSuccess(lines)
510enddef
511
512export def CheckSourceFailure(lines: list<string>, error: string, lnum = -3)
513 CheckSourceScriptFailure(lines, error, lnum)
514enddef
515
516export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3)
517 CheckSourceScriptFailureList(lines, errors, lnum)
518enddef
519
520export def CheckSourceDefAndScriptSuccess(lines: list<string>)
521 CheckSourceDefSuccess(lines)
522 CheckSourceScriptSuccess(['vim9script'] + lines)
523enddef
524
525# Execute "lines" in a legacy function, :def function and Vim9 script.
526# Use 'VAR' for a declaration.
527# Use 'LET' for an assignment
528# Use ' #"' for a comment
529export def CheckSourceLegacyAndVim9Failure(lines: list<string>, error: any)
530 var legacyError: string
531 var defError: string
532 var scriptError: string
533
534 if type(error) == type('string')
535 legacyError = error
536 defError = error
537 scriptError = error
538 else
539 legacyError = error[0]
540 defError = error[1]
541 scriptError = error[2]
542 endif
543
544 CheckSourceLegacyFailure(LegacyTrans(lines), legacyError)
545 var vim9lines = Vim9Trans(lines)
546 CheckSourceDefExecFailure(vim9lines, defError)
547 CheckSourceScriptFailure(['vim9script'] + vim9lines, scriptError)
548enddef
549