Mercurial > vim
comparison src/testdir/test55.in @ 148:72aefd4c1e0d
updated for version 7.0046
author | vimboss |
---|---|
date | Mon, 31 Jan 2005 19:19:04 +0000 |
parents | f67f8a8d81ba |
children | 8b0ee9d57d7f |
comparison
equal
deleted
inserted
replaced
147:2f5a3b881ada | 148:72aefd4c1e0d |
---|---|
1 Tests for List and Dictionary types. vim: set ft=vim : | 1 Tests for List and Dictionary types. vim: set ft=vim : |
2 | 2 |
3 STARTTEST | 3 STARTTEST |
4 :so small.vim | 4 :so small.vim |
5 :fun Test() | 5 :fun Test(...) |
6 :" Creating List directly with different types | 6 :" Creating List directly with different types |
7 :let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] | 7 :let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] |
8 :$put =string(l) | 8 :$put =string(l) |
9 :$put =string(l[-1]) | 9 :$put =string(l[-1]) |
10 :$put =string(l[-4]) | 10 :$put =string(l[-4]) |
25 :" | 25 :" |
26 :" Creating Dictionary directly with different types | 26 :" Creating Dictionary directly with different types |
27 :let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} | 27 :let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} |
28 :$put =string(d) . d.1 | 28 :$put =string(d) . d.1 |
29 :$put =string(sort(keys(d))) | 29 :$put =string(sort(keys(d))) |
30 :$put =string(values(d)) | 30 :$put =string (values(d)) |
31 :for [key, val] in items(d) | 31 :for [key, val] in items(d) |
32 : $put =key . ':' . string(val) | 32 : $put =key . ':' . string(val) |
33 : unlet key val | 33 : unlet key val |
34 :endfor | 34 :endfor |
35 :call extend(d, {3:33, 1:99}) | 35 :call extend (d, {3:33, 1:99}) |
36 :call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") | 36 :call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") |
37 :try | 37 :try |
38 : call extend(d, {3:333,4:444}, "error") | 38 : call extend(d, {3:333,4:444}, "error") |
39 :catch | 39 :catch |
40 : $put =v:exception[:15] . v:exception[-1:-1] | 40 : $put =v:exception[:15] . v:exception[-1:-1] |
66 :" | 66 :" |
67 :" removing items with :unlet | 67 :" removing items with :unlet |
68 :unlet l[2] | 68 :unlet l[2] |
69 :$put =string(l) | 69 :$put =string(l) |
70 :let l = range(8) | 70 :let l = range(8) |
71 :try | |
71 :unlet l[:3] | 72 :unlet l[:3] |
72 :unlet l[1:] | 73 :unlet l[1:] |
74 :catch | |
75 :$put =v:exception | |
76 :endtry | |
73 :$put =string(l) | 77 :$put =string(l) |
74 :" | 78 :" |
75 :unlet d.c | 79 :unlet d.c |
76 :unlet d[-1] | 80 :unlet d[-1] |
77 :$put =string(d) | 81 :$put =string(d) |
141 :" Nasty: remove func from Dict that's being called (works) | 145 :" Nasty: remove func from Dict that's being called (works) |
142 :let d = {1:1} | 146 :let d = {1:1} |
143 :func d.func(a) | 147 :func d.func(a) |
144 : return "a:". a:a | 148 : return "a:". a:a |
145 :endfunc | 149 :endfunc |
146 :$put = d.func(string(remove(d, 'func'))) | 150 :$put =d.func(string(remove(d, 'func'))) |
147 :" | 151 :" |
148 :" Nasty: deepcopy() dict that refers to itself (fails) | 152 :" Nasty: deepcopy() dict that refers to itself (fails) |
149 :let d = {1:1, 2:2} | 153 :let d = {1:1, 2:2} |
150 :let l = [4, d, 6] | 154 :let l = [4, d, 6] |
151 :let d[3] = l | 155 :let d[3] = l |
153 : let x = deepcopy(d) | 157 : let x = deepcopy(d) |
154 :catch | 158 :catch |
155 : $put =v:exception[:14] | 159 : $put =v:exception[:14] |
156 :endtry | 160 :endtry |
157 :" | 161 :" |
162 :" Locked variables | |
163 :for depth in range(5) | |
164 : $put ='depth is ' . depth | |
165 : for u in range(3) | |
166 : unlet l | |
167 : let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] | |
168 : exe "lockvar " . depth . " l" | |
169 : if u == 1 | |
170 : exe "unlockvar l" | |
171 : elseif u == 2 | |
172 : exe "unlockvar " . depth . " l" | |
173 : endif | |
174 : let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") | |
175 : $put =ps | |
176 : let ps = '' | |
177 : try | |
178 : let l[1][1][0] = 99 | |
179 : let ps .= 'p' | |
180 : catch | |
181 : let ps .= 'F' | |
182 : endtry | |
183 : try | |
184 : let l[1][1] = [99] | |
185 : let ps .= 'p' | |
186 : catch | |
187 : let ps .= 'F' | |
188 : endtry | |
189 : try | |
190 : let l[1] = [99] | |
191 : let ps .= 'p' | |
192 : catch | |
193 : let ps .= 'F' | |
194 : endtry | |
195 : try | |
196 : let l[2]['6'][7] = 99 | |
197 : let ps .= 'p' | |
198 : catch | |
199 : let ps .= 'F' | |
200 : endtry | |
201 : try | |
202 : let l[2][6] = {99: 99} | |
203 : let ps .= 'p' | |
204 : catch | |
205 : let ps .= 'F' | |
206 : endtry | |
207 : try | |
208 : let l[2] = {99: 99} | |
209 : let ps .= 'p' | |
210 : catch | |
211 : let ps .= 'F' | |
212 : endtry | |
213 : try | |
214 : let l = [99] | |
215 : let ps .= 'p' | |
216 : catch | |
217 : let ps .= 'F' | |
218 : endtry | |
219 : $put =ps | |
220 : endfor | |
221 :endfor | |
222 :" | |
223 :" a:000 function argument | |
224 :" first the tests that should fail | |
225 :try | |
226 : let a:000 = [1, 2] | |
227 :catch | |
228 : $put ='caught a:000' | |
229 :endtry | |
230 :try | |
231 : let a:000[0] = 9 | |
232 :catch | |
233 : $put ='caught a:000[0]' | |
234 :endtry | |
235 :try | |
236 : let a:000[2] = [9, 10] | |
237 :catch | |
238 : $put ='caught a:000[2]' | |
239 :endtry | |
240 :try | |
241 : let a:000[3] = {9: 10} | |
242 :catch | |
243 : $put ='caught a:000[3]' | |
244 :endtry | |
245 :" now the tests that should pass | |
246 :try | |
247 : let a:000[2][1] = 9 | |
248 : call extend(a:000[2], [5, 6]) | |
249 : let a:000[3][5] = 8 | |
250 : let a:000[3]['a'] = 12 | |
251 : $put =string(a:000) | |
252 :catch | |
253 : $put ='caught ' . v:exception | |
254 :endtry | |
255 :" | |
158 :endfun | 256 :endfun |
159 :call Test() " This may take a while | 257 :call Test(1, 2, [3, 4], {5: 6}) " This may take a while |
160 :" | 258 :" |
161 :/^start:/,$wq! test.out | 259 :/^start:/,$wq! test.out |
162 ENDTEST | 260 ENDTEST |
163 | 261 |
164 start: | 262 start: |