comparison src/testdir/test_listdict.vim @ 14856:c5a2fb8b221d v8.1.0440

patch 8.1.0440: remove() with a range not sufficiently tested commit https://github.com/vim/vim/commit/2bfddfc508bcc8dcee108f098eb75844a228fa44 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 30 17:16:25 2018 +0200 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 https://github.com/vim/vim/issues/3497)
author Christian Brabandt <cb@256bit.org>
date Sun, 30 Sep 2018 17:30:06 +0200
parents cb9b2774f21f
children 63b02fcf1361
comparison
equal deleted inserted replaced
14855:f8fd37c1d655 14856:c5a2fb8b221d
104 let l = [0] 104 let l = [0]
105 let l[:] = [1, 2] 105 let l[:] = [1, 2]
106 call assert_equal([1, 2], l) 106 call assert_equal([1, 2], l)
107 endfunc 107 endfunc
108 108
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
109 " Tests for Dictionary type 146 " Tests for Dictionary type
110 147
111 func Test_dict() 148 func Test_dict()
112 " Creating Dictionary directly with different types 149 " Creating Dictionary directly with different types
113 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} 150 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
218 endfunc 255 endfunc
219 let g:dict.foo = ['-', 2, 3] 256 let g:dict.foo = ['-', 2, 3]
220 call insert(g:dict.foo, function('strlen')) 257 call insert(g:dict.foo, function('strlen'))
221 call assert_equal('g:dict.func-4', g:dict.func()) 258 call assert_equal('g:dict.func-4', g:dict.func())
222 unlet g:dict 259 unlet g:dict
260 endfunc
261
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:')
223 endfunc 271 endfunc
224 272
225 " Nasty: remove func from Dict that's being called (works) 273 " Nasty: remove func from Dict that's being called (works)
226 func Test_dict_func_remove_in_use() 274 func Test_dict_func_remove_in_use()
227 let d = {1:1} 275 let d = {1:1}