changeset 15949:d8ab4fa99341 v8.1.0980

patch 8.1.0980: extend() insufficiently tested commit https://github.com/vim/vim/commit/58d63a0a2364e1f06a80550f9f5038145b339171 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 25 05:56:31 2019 +0100 patch 8.1.0980: extend() insufficiently tested Problem: extend() insufficiently tested. Solution: Add more tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/4040)
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 Feb 2019 06:00:04 +0100
parents 1b55571e861e
children 1bebb061a6fc
files src/testdir/test_listdict.vim src/version.c
diffstat 2 files changed, 58 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -641,19 +641,69 @@ func Test_listdict_compare_complex()
 endfunc
 
 func Test_listdict_extend()
+  " Test extend() with lists
+
   " Pass the same List to extend()
-  let l = [1, 2, 3, 4, 5]
-  call extend(l, l)
-  call assert_equal([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], l)
+  let l = [1, 2, 3]
+  call assert_equal([1, 2, 3, 1, 2, 3], extend(l, l))
+  call assert_equal([1, 2, 3, 1, 2, 3], l)
+
+  let l = [1, 2, 3]
+  call assert_equal([1, 2, 3, 4, 5, 6], extend(l, [4, 5, 6]))
+  call assert_equal([1, 2, 3, 4, 5, 6], l)
+
+  let l = [1, 2, 3]
+  call extend(l, [4, 5, 6], 0)
+  call assert_equal([4, 5, 6, 1, 2, 3], l)
+
+  let l = [1, 2, 3]
+  call extend(l, [4, 5, 6], 1)
+  call assert_equal([1, 4, 5, 6, 2, 3], l)
+
+  let l = [1, 2, 3]
+  call extend(l, [4, 5, 6], 3)
+  call assert_equal([1, 2, 3, 4, 5, 6], l)
+
+  let l = [1, 2, 3]
+  call extend(l, [4, 5, 6], -1)
+  call assert_equal([1, 2, 4, 5, 6, 3], l)
+
+  let l = [1, 2, 3]
+  call extend(l, [4, 5, 6], -3)
+  call assert_equal([4, 5, 6, 1, 2,  3], l)
+
+  let l = [1, 2, 3]
+  call assert_fails("call extend(l, [4, 5, 6], 4)", 'E684:')
+  call assert_fails("call extend(l, [4, 5, 6], -4)", 'E684:')
+  call assert_fails("call extend(l, [4, 5, 6], 1.2)", 'E805:')
+
+  " Test extend() with dictionaries.
 
   " Pass the same Dict to extend()
   let d = { 'a': {'b': 'B'}}
   call extend(d, d)
   call assert_equal({'a': {'b': 'B'}}, d)
 
-  " Pass the same Dict to extend() with "error"
-  call assert_fails("call extend(d, d, 'error')", 'E737:')
-  call assert_equal({'a': {'b': 'B'}}, d)
+  let d = {'a': 'A', 'b': 'B'}
+  call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, extend(d, {'b': 0, 'c':'C'}))
+  call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, d)
+
+  let d = {'a': 'A', 'b': 'B'}
+  call extend(d, {'a': 'A', 'b': 0, 'c': 'C'}, "force")
+  call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, d)
+
+  let d = {'a': 'A', 'b': 'B'}
+  call extend(d, {'b': 0, 'c':'C'}, "keep")
+  call assert_equal({'a': 'A', 'b': 'B', 'c': 'C'}, d)
+
+  let d = {'a': 'A', 'b': 'B'}
+  call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:')
+  call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'xxx')", 'E475:')
+  call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E806:')
+  call assert_equal({'a': 'A', 'b': 'B'}, d)
+
+  call assert_fails("call extend([1, 2], 1)", 'E712:')
+  call assert_fails("call extend([1, 2], {})", 'E712:')
 endfunc
 
 func s:check_scope_dict(x, fixed)
--- a/src/version.c
+++ b/src/version.c
@@ -780,6 +780,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    980,
+/**/
     979,
 /**/
     978,