aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-02-22 15:04:16 -0500
committerGitHub <noreply@github.com>2021-02-22 15:04:16 -0500
commitfb2adadc9ef001bccd30014f71fded089bda5b5a (patch)
treec07ac6cd00ede39244c68ace4cbbe7c382f52602 /src/nvim/testdir
parentbca19138bf3c16edad26ae34f44bb18805156a9a (diff)
parent77bae79c0724c60c80b93b9a9639aa7daf1adb68 (diff)
downloadrneovim-fb2adadc9ef001bccd30014f71fded089bda5b5a.tar.gz
rneovim-fb2adadc9ef001bccd30014f71fded089bda5b5a.tar.bz2
rneovim-fb2adadc9ef001bccd30014f71fded089bda5b5a.zip
Merge pull request #13988 from janlazo/vim-8.1.1310
vim-patch:8.1.1310: named function arguments are never optional
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r--src/nvim/testdir/test_user_func.vim53
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