diff options
| author | erw7 <erw7.github@gmail.com> | 2019-09-06 14:02:31 +0900 |
|---|---|---|
| committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-02-22 09:16:41 -0500 |
| commit | 66b0ab088344c746fe266b8098a3b3559cdc79e2 (patch) | |
| tree | 30133b4e43486b94ef547817e94aff0a198ee571 /src/nvim/testdir | |
| parent | 7bcac75f30f3ed56ebced817aff281b68854f363 (diff) | |
| download | rneovim-66b0ab088344c746fe266b8098a3b3559cdc79e2.tar.gz rneovim-66b0ab088344c746fe266b8098a3b3559cdc79e2.tar.bz2 rneovim-66b0ab088344c746fe266b8098a3b3559cdc79e2.zip | |
vim-patch:8.1.1310: named function arguments are never optional
Problem: Named function arguments are never optional.
Solution: Support optional function arguments with a default value. (Andy
Massimino, closes vim/vim#3952)
https://github.com/vim/vim/commit/42ae78cfff171fbd7412306083fe200245d7a7a6
Diffstat (limited to 'src/nvim/testdir')
| -rw-r--r-- | src/nvim/testdir/test_user_func.vim | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 67701ee3ca..e9e181ce3d 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -95,6 +95,59 @@ func Test_user_func() enew! endfunc +func Log(val, base = 10) + return log(a:val) / log(a:base) +endfunc + +func Args(mandatory, optional = v:null, ...) + return deepcopy(a:) +endfunc + +func Args2(a = 1, b = 2, c = 3) + return deepcopy(a:) +endfunc + +func MakeBadFunc() + func s:fcn(a, b=1, c) + endfunc +endfunc + +func Test_default_arg() + call assert_equal(1.0, Log(10)) + call assert_equal(log(10), Log(10, exp(1))) + call assert_fails("call Log(1,2,3)", 'E118') + + let res = Args(1) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, v:null) + call assert_equal(res['0'], 0) + + let res = Args(1,2) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, 2) + call assert_equal(res['0'], 0) + + let res = Args(1,2,3) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, 2) + call assert_equal(res['0'], 1) + + call assert_fails("call MakeBadFunc()", 'E989') + call assert_fails("fu F(a=1 ,) | endf", 'E475') + + " Since neovim does not have v:none, the ability to use the default + " argument with the intermediate argument set to v:none has been omitted. + " Therefore, this test is not performed. + " let d = Args2(7, v:none, 9) + " call assert_equal([7, 2, 9], [d.a, d.b, d.c]) + + call assert_equal("\n" + \ .. " function Args2(a = 1, b = 2, c = 3)\n" + \ .. "1 return deepcopy(a:)\n" + \ .. " endfunction", + \ execute('func Args2')) +endfunc + func Test_failed_call_in_try() try | call UnknownFunc() | catch | endtry endfunc |