diff src/testdir/test_vim9_script.vim @ 19787:906269bf83d5 v8.2.0450

patch 8.2.0450: not enough testing for restricted mode and function calls Commit: https://github.com/vim/vim/commit/7d941ee032c02a4b682201881eb5c1f1958f17ee Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 26 14:11:58 2020 +0100 patch 8.2.0450: not enough testing for restricted mode and function calls Problem: Not enough testing for restricted mode and function calls. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5847)
author Bram Moolenaar <Bram@vim.org>
date Thu, 26 Mar 2020 14:15:04 +0100
parents 99248f0ff29d
children c1c88b333481
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1004,4 +1004,62 @@ def Test_redef_failure()
   delfunc! Func2
 enddef
 
+" Test for internal functions returning different types
+func Test_InternalFuncRetType()
+  let lines =<< trim END
+    def RetFloat(): float
+      return ceil(1.456)
+    enddef
+
+    def RetListAny(): list<any>
+      return items({'k' : 'v'})
+    enddef
+
+    def RetListString(): list<string>
+      return split('a:b:c', ':')
+    enddef
+
+    def RetListDictAny(): list<dict<any>>
+      return getbufinfo()
+    enddef
+
+    def RetDictNumber(): dict<number>
+      return wordcount()
+    enddef
+
+    def RetDictString(): dict<string>
+      return environ()
+    enddef
+  END
+  call writefile(lines, 'Xscript')
+  source Xscript
+
+  call assert_equal(2.0, RetFloat())
+  call assert_equal([['k', 'v']], RetListAny())
+  call assert_equal(['a', 'b', 'c'], RetListString())
+  call assert_notequal([], RetListDictAny())
+  call assert_notequal({}, RetDictNumber())
+  call assert_notequal({}, RetDictString())
+  call delete('Xscript')
+endfunc
+
+" Test for passing too many or too few arguments to internal functions
+func Test_internalfunc_arg_error()
+  let l =<< trim END
+    def! FArgErr(): float
+      return ceil(1.1, 2)
+    enddef
+  END
+  call writefile(l, 'Xinvalidarg')
+  call assert_fails('so Xinvalidarg', 'E118:')
+  let l =<< trim END
+    def! FArgErr(): float
+      return ceil()
+    enddef
+  END
+  call writefile(l, 'Xinvalidarg')
+  call assert_fails('so Xinvalidarg', 'E119:')
+  call delete('Xinvalidarg')
+endfunc
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker