diff options
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_user_func.vim | 32 | ||||
-rw-r--r-- | src/testdir/test_vim9_disassemble.vim | 15 | ||||
-rw-r--r-- | src/testdir/test_vim9_func.vim | 30 |
3 files changed, 77 insertions, 0 deletions
diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim index f6e25e3b5a..af05812c6b 100644 --- a/src/testdir/test_user_func.vim +++ b/src/testdir/test_user_func.vim @@ -529,4 +529,36 @@ func Test_funcdef_alloc_failure() bw! endfunc +func AddDefer(arg) + call extend(g:deferred, [a:arg]) +endfunc + +func WithDeferTwo() + call extend(g:deferred, ['in Two']) + for nr in range(3) + defer AddDefer('Two' .. nr) + endfor + call extend(g:deferred, ['end Two']) +endfunc + +func WithDeferOne() + call extend(g:deferred, ['in One']) + call writefile(['text'], 'Xfuncdefer') + defer delete('Xfuncdefer') + defer AddDefer('One') + call WithDeferTwo() + call extend(g:deferred, ['end One']) +endfunc + +func Test_defer() + let g:deferred = [] + call WithDeferOne() + + call assert_equal(['in One', 'in Two', 'end Two', 'Two2', 'Two1', 'Two0', 'end One', 'One'], g:deferred) + unlet g:deferred + + call assert_equal('', glob('Xfuncdefer')) +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim index 12be156483..57b385bd50 100644 --- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -2900,4 +2900,19 @@ def Test_disassemble_bitshift() '10 RETURN void', instr) enddef +def s:OneDefer() + defer delete("file") +enddef + +def Test_disassemble_defer() + var instr = execute('disassemble s:OneDefer') + assert_match('OneDefer\_s*' .. + 'defer delete("file")\_s*' .. + '\d PUSHFUNC "delete"\_s*' .. + '\d PUSHS "file"\_s*' .. + '\d DEFER 1 args\_s*' .. + '\d RETURN\_s*', + instr) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 0fa74df259..c616e1890d 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -4272,6 +4272,36 @@ def Test_cexpr_errmsg_line_number() v9.CheckScriptFailure(lines, 'E777', 2) enddef +def AddDefer(s: string) + g:deferred->extend([s]) +enddef + +def DeferTwo() + g:deferred->extend(['in Two']) + for n in range(3) + defer g:AddDefer('two' .. n) + endfor + g:deferred->extend(['end Two']) +enddef + +def DeferOne() + g:deferred->extend(['in One']) + defer g:AddDefer('one') + g:DeferTwo() + g:deferred->extend(['end One']) + + writefile(['text'], 'XdeferFile') + defer delete('XdeferFile') +enddef + +def Test_defer() + g:deferred = [] + g:DeferOne() + assert_equal(['in One', 'in Two', 'end Two', 'two2', 'two1', 'two0', 'end One', 'one'], g:deferred) + unlet g:deferred + assert_equal('', glob('XdeferFile')) +enddef + " The following messes up syntax highlight, keep near the end. if has('python3') def Test_python3_command() |