diff options
author | Michael Ennen <mike.ennen@gmail.com> | 2016-12-14 00:20:48 -0700 |
---|---|---|
committer | Michael Ennen <mike.ennen@gmail.com> | 2017-02-14 17:38:16 -0700 |
commit | bb2afeb0266ffd410e2e226a376f7ddbac633491 (patch) | |
tree | 0488197944e3fc6a7c5ddf887eebc545c9f34c8b /src/nvim/testdir/test_partial.vim | |
parent | b0fc6108c923a198325354ae36b71f90c4c68e19 (diff) | |
download | rneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.tar.gz rneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.tar.bz2 rneovim-bb2afeb0266ffd410e2e226a376f7ddbac633491.zip |
vim-patch:7.4.1989
Problem: filter() and map() only accept a string argument.
Solution: Implement using a Funcref argument (Yasuhiro Matsumoto, Ken
Takata)
https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Diffstat (limited to 'src/nvim/testdir/test_partial.vim')
-rw-r--r-- | src/nvim/testdir/test_partial.vim | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 3a6e162453..de5c26c2dd 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -14,6 +14,14 @@ func MySort(up, one, two) return a:one < a:two ? 1 : -1 endfunc +func MyMap(sub, index, val) + return a:val - a:sub +endfunc + +func MyFilter(threshold, index, val) + return a:val > a:threshold +endfunc + func Test_partial_args() let Cb = function('MyFunc', ["foo", "bar"]) @@ -36,6 +44,16 @@ func Test_partial_args() call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) let Sort = function('MySort', [0]) call assert_equal([3, 2, 1], sort([3, 1, 2], Sort)) + + let Map = function('MyMap', [2]) + call assert_equal([-1, 0, 1], map([1, 2, 3], Map)) + let Map = function('MyMap', [3]) + call assert_equal([-2, -1, 0], map([1, 2, 3], Map)) + + let Filter = function('MyFilter', [1]) + call assert_equal([2, 3], filter([1, 2, 3], Filter)) + let Filter = function('MyFilter', [2]) + call assert_equal([3], filter([1, 2, 3], Filter)) endfunc func MyDictFunc(arg1, arg2) dict @@ -59,6 +77,9 @@ func Test_partial_dict() call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) call assert_fails('Cb("fff")', 'E492:') + let Cb = function('MyDictFunc', dict) + call assert_equal({"foo": "hello/foo/1", "bar": "hello/bar/2"}, map({"foo": 1, "bar": 2}, Cb)) + let dict = {"tr": function('tr', ['hello', 'h', 'H'])} call assert_equal("Hello", dict.tr()) endfunc |