comparison src/testdir/test_vim9_func.vim @ 30065:6cf788ab844c v9.0.0370

patch 9.0.0370: cleaning up afterwards can make a function messy Commit: https://github.com/vim/vim/commit/1d84f7608f1e41dad03b8cc7925895437775f7c0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 3 21:35:53 2022 +0100 patch 9.0.0370: cleaning up afterwards can make a function messy Problem: Cleaning up afterwards can make a function messy. Solution: Add the :defer command.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Sep 2022 22:45:03 +0200
parents 111d97d7b93a
children ba22d5536d3e
comparison
equal deleted inserted replaced
30064:a8f1fbaa43c8 30065:6cf788ab844c
4270 Func() 4270 Func()
4271 END 4271 END
4272 v9.CheckScriptFailure(lines, 'E777', 2) 4272 v9.CheckScriptFailure(lines, 'E777', 2)
4273 enddef 4273 enddef
4274 4274
4275 def AddDefer(s: string)
4276 g:deferred->extend([s])
4277 enddef
4278
4279 def DeferTwo()
4280 g:deferred->extend(['in Two'])
4281 for n in range(3)
4282 defer g:AddDefer('two' .. n)
4283 endfor
4284 g:deferred->extend(['end Two'])
4285 enddef
4286
4287 def DeferOne()
4288 g:deferred->extend(['in One'])
4289 defer g:AddDefer('one')
4290 g:DeferTwo()
4291 g:deferred->extend(['end One'])
4292
4293 writefile(['text'], 'XdeferFile')
4294 defer delete('XdeferFile')
4295 enddef
4296
4297 def Test_defer()
4298 g:deferred = []
4299 g:DeferOne()
4300 assert_equal(['in One', 'in Two', 'end Two', 'two2', 'two1', 'two0', 'end One', 'one'], g:deferred)
4301 unlet g:deferred
4302 assert_equal('', glob('XdeferFile'))
4303 enddef
4304
4275 " The following messes up syntax highlight, keep near the end. 4305 " The following messes up syntax highlight, keep near the end.
4276 if has('python3') 4306 if has('python3')
4277 def Test_python3_command() 4307 def Test_python3_command()
4278 py3 import vim 4308 py3 import vim
4279 py3 vim.command("g:done = 'yes'") 4309 py3 vim.command("g:done = 'yes'")