diff src/testdir/test_vim9_builtin.vim @ 23800:57f0e3fd7c05 v8.2.2441

patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch Commit: https://github.com/vim/vim/commit/c03f5c677a1fba99d2379550ccf2391eaa43e2ac Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 31 17:48:30 2021 +0100 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch Problem: Vim9: extend() does not give an error for a type mismatch. Solution: Check the type of the second argument. (closes https://github.com/vim/vim/issues/7760)
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 Jan 2021 18:00:04 +0100
parents d12ef361d9de
children 007fa6365dfb
line wrap: on
line diff
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -240,19 +240,24 @@ def Test_expand()
 enddef
 
 def Test_extend_arg_types()
-  assert_equal([1, 2, 3], extend([1, 2], [3]))
-  assert_equal([3, 1, 2], extend([1, 2], [3], 0))
-  assert_equal([1, 3, 2], extend([1, 2], [3], 1))
-  assert_equal([1, 3, 2], extend([1, 2], [3], s:number_one))
+  g:number_one = 1
+  g:string_keep = 'keep'
+  var lines =<< trim END
+      assert_equal([1, 2, 3], extend([1, 2], [3]))
+      assert_equal([3, 1, 2], extend([1, 2], [3], 0))
+      assert_equal([1, 3, 2], extend([1, 2], [3], 1))
+      assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
 
-  assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
-  assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
-  assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
-  assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, s:string_keep))
+      assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
+      assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
+      assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
+      assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
 
-  var res: list<dict<any>>
-  extend(res, mapnew([1, 2], (_, v) => ({})))
-  assert_equal([{}, {}], res)
+      var res: list<dict<any>>
+      extend(res, mapnew([1, 2], (_, v) => ({})))
+      assert_equal([{}, {}], res)
+  END
+  CheckDefAndScriptSuccess(lines)
 
   CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
   CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
@@ -300,8 +305,7 @@ def Test_extend_dict_item_type()
        var d: dict<number> = {a: 1}
        extend(d, {b: 'x'})
   END
-  CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
-  CheckScriptFailure(['vim9script'] + lines, 'E1012:', 3)
+  CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
 
   lines =<< trim END
        var d: dict<number> = {a: 1}
@@ -326,8 +330,7 @@ def Test_extend_list_item_type()
        var l: list<number> = [1]
        extend(l, ['x'])
   END
-  CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
-  CheckScriptFailure(['vim9script'] + lines, 'E1012:', 3)
+  CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
 
   lines =<< trim END
        var l: list<number> = [1]