Skip to content

Commit 2bfddfc

Browse files
committed
patch 8.1.0440: remove() with a range not sufficiently tested
Problem: remove() with a range not sufficiently tested. Solution: Add a test. (Dominique Pelle, closes #3497)
1 parent 438d176 commit 2bfddfc

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/testdir/test_listdict.vim

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,43 @@ func Test_list_range_assign()
106106
call assert_equal([1, 2], l)
107107
endfunc
108108

109+
" Test removing items in list
110+
func Test_list_func_remove()
111+
" Test removing 1 element
112+
let l = [1, 2, 3, 4]
113+
call assert_equal(1, remove(l, 0))
114+
call assert_equal([2, 3, 4], l)
115+
116+
let l = [1, 2, 3, 4]
117+
call assert_equal(2, remove(l, 1))
118+
call assert_equal([1, 3, 4], l)
119+
120+
let l = [1, 2, 3, 4]
121+
call assert_equal(4, remove(l, -1))
122+
call assert_equal([1, 2, 3], l)
123+
124+
" Test removing range of element(s)
125+
let l = [1, 2, 3, 4]
126+
call assert_equal([3], remove(l, 2, 2))
127+
call assert_equal([1, 2, 4], l)
128+
129+
let l = [1, 2, 3, 4]
130+
call assert_equal([2, 3], remove(l, 1, 2))
131+
call assert_equal([1, 4], l)
132+
133+
let l = [1, 2, 3, 4]
134+
call assert_equal([2, 3], remove(l, -3, -2))
135+
call assert_equal([1, 4], l)
136+
137+
" Test invalid cases
138+
let l = [1, 2, 3, 4]
139+
call assert_fails("call remove(l, 5)", 'E684:')
140+
call assert_fails("call remove(l, 1, 5)", 'E684:')
141+
call assert_fails("call remove(l, 3, 2)", 'E16:')
142+
call assert_fails("call remove(1, 0)", 'E712:')
143+
call assert_fails("call remove(l, l)", 'E745:')
144+
endfunc
145+
109146
" Tests for Dictionary type
110147

111148
func Test_dict()
@@ -222,6 +259,17 @@ func Test_script_local_dict_func()
222259
unlet g:dict
223260
endfunc
224261

262+
" Test removing items in la dictionary
263+
func Test_dict_func_remove()
264+
let d = {1:'a', 2:'b', 3:'c'}
265+
call assert_equal('b', remove(d, 2))
266+
call assert_equal({1:'a', 3:'c'}, d)
267+
268+
call assert_fails("call remove(d, 1, 2)", 'E118:')
269+
call assert_fails("call remove(d, 'a')", 'E716:')
270+
call assert_fails("call remove(d, [])", 'E730:')
271+
endfunc
272+
225273
" Nasty: remove func from Dict that's being called (works)
226274
func Test_dict_func_remove_in_use()
227275
let d = {1:1}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
440,
797799
/**/
798800
439,
799801
/**/

0 commit comments

Comments
 (0)