summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-09-30 17:16:25 +0200
committerBram Moolenaar <Bram@vim.org>2018-09-30 17:16:25 +0200
commit2bfddfc508bcc8dcee108f098eb75844a228fa44 (patch)
treee44113725f55e84f720b1729f9a73eac818826f5
parent438d176e35c16d56ff3bb7a80300197ce5a30c4f (diff)
downloadvim-git-2bfddfc508bcc8dcee108f098eb75844a228fa44.tar.gz
patch 8.1.0440: remove() with a range not sufficiently testedv8.1.0440
Problem: remove() with a range not sufficiently tested. Solution: Add a test. (Dominique Pelle, closes #3497)
-rw-r--r--src/testdir/test_listdict.vim48
-rw-r--r--src/version.c2
2 files changed, 50 insertions, 0 deletions
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index 023332c90..999d4dbd4 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -106,6 +106,43 @@ func Test_list_range_assign()
call assert_equal([1, 2], l)
endfunc
+" Test removing items in list
+func Test_list_func_remove()
+ " Test removing 1 element
+ let l = [1, 2, 3, 4]
+ call assert_equal(1, remove(l, 0))
+ call assert_equal([2, 3, 4], l)
+
+ let l = [1, 2, 3, 4]
+ call assert_equal(2, remove(l, 1))
+ call assert_equal([1, 3, 4], l)
+
+ let l = [1, 2, 3, 4]
+ call assert_equal(4, remove(l, -1))
+ call assert_equal([1, 2, 3], l)
+
+ " Test removing range of element(s)
+ let l = [1, 2, 3, 4]
+ call assert_equal([3], remove(l, 2, 2))
+ call assert_equal([1, 2, 4], l)
+
+ let l = [1, 2, 3, 4]
+ call assert_equal([2, 3], remove(l, 1, 2))
+ call assert_equal([1, 4], l)
+
+ let l = [1, 2, 3, 4]
+ call assert_equal([2, 3], remove(l, -3, -2))
+ call assert_equal([1, 4], l)
+
+ " Test invalid cases
+ let l = [1, 2, 3, 4]
+ call assert_fails("call remove(l, 5)", 'E684:')
+ call assert_fails("call remove(l, 1, 5)", 'E684:')
+ call assert_fails("call remove(l, 3, 2)", 'E16:')
+ call assert_fails("call remove(1, 0)", 'E712:')
+ call assert_fails("call remove(l, l)", 'E745:')
+endfunc
+
" Tests for Dictionary type
func Test_dict()
@@ -222,6 +259,17 @@ func Test_script_local_dict_func()
unlet g:dict
endfunc
+" Test removing items in la dictionary
+func Test_dict_func_remove()
+ let d = {1:'a', 2:'b', 3:'c'}
+ call assert_equal('b', remove(d, 2))
+ call assert_equal({1:'a', 3:'c'}, d)
+
+ call assert_fails("call remove(d, 1, 2)", 'E118:')
+ call assert_fails("call remove(d, 'a')", 'E716:')
+ call assert_fails("call remove(d, [])", 'E730:')
+endfunc
+
" Nasty: remove func from Dict that's being called (works)
func Test_dict_func_remove_in_use()
let d = {1:1}
diff --git a/src/version.c b/src/version.c
index 1f1403003..e6f7e1ed5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 440,
+/**/
439,
/**/
438,