1" Utility functions for testing vim9 script 2 3" Use a different file name for each run. 4let s:sequence = 1 5 6" Check that "lines" inside a ":def" function has no error. 7func CheckDefSuccess(lines) 8 let fname = 'Xdef' .. s:sequence 9 let s:sequence += 1 10 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname) 11 exe 'so ' .. fname 12 call Func() 13 delfunc! Func 14 call delete(fname) 15endfunc 16 17" Check that "lines" inside ":def" results in an "error" message. 18" If "lnum" is given check that the error is reported for this line. 19" Add a line before and after to make it less likely that the line number is 20" accidentally correct. 21func CheckDefFailure(lines, error, lnum = -3) 22 let fname = 'Xdef' .. s:sequence 23 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname) 24 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1) 25 delfunc! Func 26 call delete(fname) 27 let s:sequence += 1 28endfunc 29 30" Check that "lines" inside ":def" results in an "error" message when executed. 31" If "lnum" is given check that the error is reported for this line. 32" Add a line before and after to make it less likely that the line number is 33" accidentally correct. 34func CheckDefExecFailure(lines, error, lnum = -3) 35 let fname = 'Xdef' .. s:sequence 36 let s:sequence += 1 37 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname) 38 exe 'so ' .. fname 39 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1) 40 delfunc! Func 41 call delete(fname) 42endfunc 43 44def CheckScriptFailure(lines: list<string>, error: string, lnum = -3) 45 var fname = 'Xdef' .. s:sequence 46 s:sequence += 1 47 writefile(lines, fname) 48 assert_fails('so ' .. fname, error, lines, lnum) 49 delete(fname) 50enddef 51 52def CheckScriptSuccess(lines: list<string>) 53 var fname = 'Xdef' .. s:sequence 54 s:sequence += 1 55 writefile(lines, fname) 56 exe 'so ' .. fname 57 delete(fname) 58enddef 59 60def CheckDefAndScriptSuccess(lines: list<string>) 61 CheckDefSuccess(lines) 62 CheckScriptSuccess(['vim9script'] + lines) 63enddef 64 65" Check that a command fails with the same error when used in a :def function 66" and when used in Vim9 script. 67def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3) 68 CheckDefFailure(lines, error, lnum) 69 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) 70enddef 71 72" Check that a command fails with the same error when executed in a :def 73" function and when used in Vim9 script. 74def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3) 75 CheckDefExecFailure(lines, error, lnum) 76 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) 77enddef 78