Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 20279:49b50843e725 v8.2.0695
patch 8.2.0695: Vim9: cannot define a function inside a function
Commit: https://github.com/vim/vim/commit/04b12697838b232b8b17c553ccc74cf1f1bdb81c
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon May 4 23:24:44 2020 +0200
patch 8.2.0695: Vim9: cannot define a function inside a function
Problem: Vim9: cannot define a function inside a function.
Solution: Initial support for :def inside :def.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 04 May 2020 23:30:04 +0200 |
parents | 350bb78345ba |
children | ab8c8fd0f868 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -2,19 +2,7 @@ source check.vim source view_util.vim - -" Check that "lines" inside ":def" results in an "error" message. -func CheckDefFailure(lines, error) - call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef') - call assert_fails('so Xdef', a:error, a:lines) - call delete('Xdef') -endfunc - -func CheckScriptFailure(lines, error) - call writefile(a:lines, 'Xdef') - call assert_fails('so Xdef', a:error, a:lines) - call delete('Xdef') -endfunc +source vim9.vim func Test_def_basic() def SomeFunc(): string @@ -95,8 +83,17 @@ def Test_call_default_args() assert_equal('one', MyDefaultArgs('one')) assert_fails('call MyDefaultArgs("one", "two")', 'E118:') - call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:') - call CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string') + CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:') + CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string') +enddef + +def Test_nested_function() + def Nested(arg: string): string + return 'nested ' .. arg + enddef + assert_equal('nested function', Nested('function')) + + CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:') enddef func Test_call_default_args_from_func() @@ -721,5 +718,13 @@ def Test_closure_using_argument() unlet g:UseVararg enddef +def Test_nested_closure() + let local = 'text' + def Closure(arg: string): string + return local .. arg + enddef + assert_equal('text!!!', Closure('!!!')) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker