]> granicus.if.org Git - vim/commitdiff
patch 8.2.2098: Vim9: function argument of sort() and map() not tested v8.2.2098
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Dec 2020 20:47:06 +0000 (21:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Dec 2020 20:47:06 +0000 (21:47 +0100)
Problem:    Vim9: function argument of sort() and map() not tested.
Solution:   Add a couple of tests.

src/testdir/test_vim9_builtin.vim
src/version.c

index 301b270e695f3cd0ac04c323a2932a4b36c8b59a..50b711f8db7817ac0f81bf32267d4ea0172586ff 100644 (file)
@@ -229,6 +229,18 @@ def Wrong_dict_key_type(items: list<number>): list<number>
   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()
index 95f3f62e7e83058cf87f89697390df7bbf13cf90..a24a261fd6d9053cae5c59b816aedac1997e00b9 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2098,
 /**/
     2097,
 /**/