summaryrefslogtreecommitdiff
path: root/src/testdir/test_vim9_builtin.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-08-14 12:07:11 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-14 12:07:11 +0100
commit63acae13f57c5ad4c8ec3146d0c458550b9e984e (patch)
tree50a6a623dcce89ae1f639c4c2e2f62904aee8840 /src/testdir/test_vim9_builtin.vim
parentc9b6570fab46bf2c246a954cfb8c0d95fe2746b3 (diff)
downloadvim-git-63acae13f57c5ad4c8ec3146d0c458550b9e984e.tar.gz
patch 9.0.0204: indexof() may leak memoryv9.0.0204
Problem: indexof() may leak memory. Solution: Free allocated values. (Yegappan Lakshmanan, closes #10916)
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r--src/testdir/test_vim9_builtin.vim30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 244021c7e..55ede984d 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -2074,10 +2074,36 @@ def Test_indexof()
var b = 0zdeadbeef
indexof(b, "v:val == 0xef")->assert_equal(3)
- def TestIdx(k: number, v: dict<any>): bool
+ def TestIdx1(k: number, v: dict<any>): bool
return v.color == 'blue'
enddef
- indexof(l, TestIdx)->assert_equal(1)
+ indexof(l, TestIdx1)->assert_equal(1)
+
+ var lines =<< trim END
+ def TestIdx(v: dict<any>): bool
+ return v.color == 'blue'
+ enddef
+
+ indexof([{color: "red"}], TestIdx)
+ END
+ v9.CheckDefAndScriptFailure(lines, ['E176: Invalid number of arguments', 'E118: Too many arguments for function'])
+
+ lines =<< trim END
+ def TestIdx(k: number, v: dict<any>)
+ enddef
+
+ indexof([{color: "red"}], TestIdx)
+ END
+ v9.CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(?number, ?any): bool', 'E1031: Cannot use void value'])
+
+ lines =<< trim END
+ def TestIdx(k: number, v: dict<any>): string
+ return "abc"
+ enddef
+
+ indexof([{color: "red"}], TestIdx)
+ END
+ v9.CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(?number, ?any): bool', 'E1135: Using a String as a Bool'])
enddef
def Test_input()