diff options
Diffstat (limited to 'src/testdir/vim9.vim')
-rw-r--r-- | src/testdir/vim9.vim | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim index f17f141dba..e05f8590bb 100644 --- a/src/testdir/vim9.vim +++ b/src/testdir/vim9.vim @@ -133,3 +133,38 @@ def CheckDefExecAndScriptFailure2( CheckDefExecFailure(lines, errorDef, lnum) CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) enddef + + +" Check that "lines" inside a legacy function has no error. +func CheckLegacySuccess(lines) + let cwd = getcwd() + let fname = 'XlegacySuccess' .. s:sequence + let s:sequence += 1 + call writefile(['func Func()'] + a:lines + ['endfunc'], fname) + try + exe 'so ' .. fname + call Func() + delfunc! Func + finally + call chdir(cwd) + call delete(fname) + endtry +endfunc + +" Execute "lines" in a legacy function, :def function and Vim9 script. +" Use 'VAR' for a declaration. +" Use 'LET' for an assignment +" Use ' #"' for a comment +def CheckLegacyAndVim9Success(lines: list<string>) + var legacylines = lines->mapnew((_, v) => + v->substitute('\<VAR\>', 'let', 'g') + ->substitute('\<LET\>', 'let', 'g') + ->substitute('#"', ' "', 'g')) + CheckLegacySuccess(legacylines) + + var vim9lines = lines->mapnew((_, v) => + v->substitute('\<VAR\>', 'var', 'g') + ->substitute('\<LET ', '', 'g')) + CheckDefSuccess(vim9lines) + CheckScriptSuccess(['vim9script'] + vim9lines) +enddef |