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