changeset 23104:1013a97d5dc0 v8.2.2098

patch 8.2.2098: Vim9: function argument of sort() and map() not tested Commit: https://github.com/vim/vim/commit/08cf0c0d82c7edfcbfe60db34f92759b7fee939a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 5 21:47:06 2020 +0100 patch 8.2.2098: Vim9: function argument of sort() and map() not tested Problem: Vim9: function argument of sort() and map() not tested. Solution: Add a couple of tests.
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Dec 2020 22:00:03 +0100
parents 9a87fcd1fce9
children 65d66ab963c2
files src/testdir/test_vim9_builtin.vim src/version.c
diffstat 2 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -229,6 +229,18 @@ def Wrong_dict_key_type(items: list<numb
   return filter(items, {_, val -> get({[val]: 1}, 'x')})
 enddef
 
+def Test_map_function_arg()
+  var lines =<< trim END
+      def MapOne(i: number, v: string): string
+        return i .. ':' .. v
+      enddef
+      var l = ['a', 'b', 'c']
+      map(l, MapOne)
+      assert_equal(['0:a', '1:b', '2:c'], l)
+  END
+  CheckDefAndScriptSuccess(lines)
+enddef
+
 def Test_filter_wrong_dict_key_type()
   assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1012:')
 enddef
@@ -523,8 +535,18 @@ def Test_sort_return_type()
 enddef
 
 def Test_sort_argument()
-  var res = ['b', 'a', 'c']->sort('i')
-  res->assert_equal(['a', 'b', 'c'])
+  var lines =<< trim END
+    var res = ['b', 'a', 'c']->sort('i')
+    res->assert_equal(['a', 'b', 'c'])
+
+    def Compare(a: number, b: number): number
+      return a - b
+    enddef
+    var l = [3, 6, 7, 1, 8, 2, 4, 5]
+    sort(l, Compare)
+    assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
+  END
+  CheckDefAndScriptSuccess(lines)
 enddef
 
 def Test_split()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2098,
+/**/
     2097,
 /**/
     2096,