annotate src/testdir/test55.in @ 2412:ca3f40b0d95e vim73

Prepare for 7.3b release. Fix src/Makefile enabling python3 by default.
author Bram Moolenaar <bram@vim.org>
date Sun, 25 Jul 2010 17:42:45 +0200
parents b62965091b8d
children fcb916bed51a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
1 Tests for List and Dictionary types. vim: set ft=vim :
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
2
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
3 STARTTEST
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
4 :so small.vim
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
5 :fun Test(...)
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
6 :" Creating List directly with different types
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
7 :let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
8 :$put =string(l)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
9 :$put =string(l[-1])
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
10 :$put =string(l[-4])
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
11 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
12 : $put =string(l[-5])
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
13 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
14 : $put =v:exception[:14]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
15 :endtry
842
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
16 :" List slices
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
17 :$put =string(l[:])
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
18 :$put =string(l[1:])
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
19 :$put =string(l[:-2])
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
20 :$put =string(l[0:8])
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
21 :$put =string(l[8:-1])
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
22 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
23 :" List identity
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
24 :let ll = l
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
25 :let lx = copy(l)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
26 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
27 : $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . (l is lx) . (l isnot lx)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
28 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
29 : $put =v:exception
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
30 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
31 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
32 :" Creating Dictionary directly with different types
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
33 :let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
34 :$put =string(d) . d.1
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
35 :$put =string(sort(keys(d)))
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
36 :$put =string (values(d))
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
37 :for [key, val] in items(d)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
38 : $put =key . ':' . string(val)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
39 : unlet key val
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
40 :endfor
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
41 :call extend (d, {3:33, 1:99})
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
42 :call extend(d, {'b':'bbb', 'c':'ccc'}, "keep")
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
43 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
44 : call extend(d, {3:333,4:444}, "error")
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
45 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
46 : $put =v:exception[:15] . v:exception[-1:-1]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
47 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
48 :$put =string(d)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
49 :call filter(d, 'v:key =~ ''[ac391]''')
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
50 :$put =string(d)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
51 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
52 :" Dictionary identity
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
53 :let dd = d
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
54 :let dx = copy(d)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
55 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
56 : $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . (d isnot dx)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
57 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
58 : $put =v:exception
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
59 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
60 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
61 :" Changing var type should fail
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
62 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
63 : let d = []
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
64 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
65 : $put =v:exception[:14] . v:exception[-1:-1]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
66 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
67 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
68 : let l = {}
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
69 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
70 : $put =v:exception[:14] . v:exception[-1:-1]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
71 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
72 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
73 :" removing items with :unlet
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
74 :unlet l[2]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
75 :$put =string(l)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
76 :let l = range(8)
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
77 :try
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
78 :unlet l[:3]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
79 :unlet l[1:]
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
80 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
81 :$put =v:exception
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
82 :endtry
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
83 :$put =string(l)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
84 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
85 :unlet d.c
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
86 :unlet d[-1]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
87 :$put =string(d)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
88 :"
842
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
89 :" removing items out of range: silently skip items that don't exist
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
90 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
91 :unlet l[2:1]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
92 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
93 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
94 :unlet l[2:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
95 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
96 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
97 :unlet l[2:3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
98 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
99 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
100 :unlet l[2:4]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
101 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
102 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
103 :unlet l[2:5]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
104 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
105 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
106 :unlet l[-1:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
107 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
108 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
109 :unlet l[-2:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
110 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
111 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
112 :unlet l[-3:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
113 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
114 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
115 :unlet l[-4:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
116 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
117 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
118 :unlet l[-5:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
119 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
120 let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
121 :unlet l[-6:2]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
122 :$put =string(l)
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
123 :"
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
124 :" assignment to a list
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
125 :let l = [0, 1, 2, 3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
126 :let [va, vb] = l[2:3]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
127 :$put =va
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
128 :$put =vb
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
129 :try
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
130 : let [va, vb] = l
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
131 :catch
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
132 : $put =v:exception[:14]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
133 :endtry
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
134 :try
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
135 : let [va, vb] = l[1:1]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
136 :catch
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
137 : $put =v:exception[:14]
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
138 :endtry
a209672376fd updated for version 7.0f
vimboss
parents: 294
diff changeset
139 :"
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
140 :" manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
141 :let d = {}
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
142 :for i in range(1500)
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
143 : let d[i] = 3000 - i
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
144 :endfor
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
145 :$put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . d[1499]
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
146 :try
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
147 : let n = d[1500]
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
148 :catch
1539
b62965091b8d updated for version 7.1-254
vimboss
parents: 1405
diff changeset
149 : $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '')
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
150 :endtry
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
151 :" lookup each items
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
152 :for i in range(1500)
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
153 : if d[i] != 3000 - i
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
154 : $put =d[i]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
155 : endif
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
156 :endfor
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
157 : let i += 1
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
158 :" delete even items
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
159 :while i >= 2
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
160 : let i -= 2
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
161 : unlet d[i]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
162 :endwhile
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
163 :$put =get(d, 1500 - 100, 'NONE') . ' ' . d[1]
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
164 :" delete odd items, checking value, one intentionally wrong
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
165 :let d[33] = 999
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
166 :let i = 1
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
167 :while i < 1500
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
168 : if d[i] != 3000 - i
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
169 : $put =i . '=' . d[i]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
170 : else
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
171 : unlet d[i]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
172 : endif
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
173 : let i += 2
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
174 :endwhile
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
175 :$put =string(d) " must be almost empty now
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
176 :unlet d
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
177 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
178 :" Dictionary function
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
179 :let dict = {}
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
180 :func dict.func(a) dict
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
181 : $put =a:a . len(self.data)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
182 :endfunc
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
183 :let dict.data = [1,2,3]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
184 :call dict.func("len: ")
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
185 :let x = dict.func("again: ")
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
186 :try
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
187 : let Fn = dict.func
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
188 : call Fn('xxx')
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
189 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
190 : $put =v:exception[:15]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
191 :endtry
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
192 :"
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
193 :" Function in script-local List or Dict
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
194 :let g:dict = {}
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
195 :function g:dict.func() dict
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
196 : $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf')
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
197 :endfunc
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
198 :let g:dict.foo = ['-', 2, 3]
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
199 :call insert(g:dict.foo, function('strlen'))
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 119
diff changeset
200 :call g:dict.func()
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
201 :"
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
202 :" Nasty: remove func from Dict that's being called (works)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
203 :let d = {1:1}
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
204 :func d.func(a)
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
205 : return "a:". a:a
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
206 :endfunc
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
207 :$put =d.func(string(remove(d, 'func')))
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
208 :"
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
209 :" Nasty: deepcopy() dict that refers to itself (fails when noref used)
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
210 :let d = {1:1, 2:2}
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
211 :let l = [4, d, 6]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
212 :let d[3] = l
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
213 :let dc = deepcopy(d)
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
214 :try
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
215 : let dc = deepcopy(d, 1)
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
216 :catch
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
217 : $put =v:exception[:14]
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
218 :endtry
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
219 :let l2 = [0, l, l, 3]
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
220 :let l[1] = l2
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
221 :let l3 = deepcopy(l2)
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
222 :$put ='same list: ' . (l3[1] is l3[2])
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
223 :"
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
224 :" Locked variables
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
225 :for depth in range(5)
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
226 : $put ='depth is ' . depth
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
227 : for u in range(3)
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
228 : unlet l
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
229 : let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
230 : exe "lockvar " . depth . " l"
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
231 : if u == 1
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
232 : exe "unlockvar l"
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
233 : elseif u == 2
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
234 : exe "unlockvar " . depth . " l"
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
235 : endif
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
236 : 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]")
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
237 : $put =ps
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
238 : let ps = ''
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
239 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
240 : let l[1][1][0] = 99
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
241 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
242 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
243 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
244 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
245 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
246 : let l[1][1] = [99]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
247 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
248 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
249 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
250 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
251 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
252 : let l[1] = [99]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
253 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
254 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
255 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
256 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
257 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
258 : let l[2]['6'][7] = 99
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
259 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
260 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
261 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
262 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
263 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
264 : let l[2][6] = {99: 99}
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
265 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
266 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
267 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
268 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
269 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
270 : let l[2] = {99: 99}
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
271 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
272 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
273 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
274 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
275 : try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
276 : let l = [99]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
277 : let ps .= 'p'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
278 : catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
279 : let ps .= 'F'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
280 : endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
281 : $put =ps
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
282 : endfor
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
283 :endfor
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
284 :"
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
285 :" a:000 function argument
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
286 :" first the tests that should fail
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
287 :try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
288 : let a:000 = [1, 2]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
289 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
290 : $put ='caught a:000'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
291 :endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
292 :try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
293 : let a:000[0] = 9
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
294 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
295 : $put ='caught a:000[0]'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
296 :endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
297 :try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
298 : let a:000[2] = [9, 10]
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
299 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
300 : $put ='caught a:000[2]'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
301 :endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
302 :try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
303 : let a:000[3] = {9: 10}
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
304 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
305 : $put ='caught a:000[3]'
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
306 :endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
307 :" now the tests that should pass
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
308 :try
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
309 : let a:000[2][1] = 9
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
310 : call extend(a:000[2], [5, 6])
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
311 : let a:000[3][5] = 8
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
312 : let a:000[3]['a'] = 12
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
313 : $put =string(a:000)
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
314 :catch
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
315 : $put ='caught ' . v:exception
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
316 :endtry
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
317 :"
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
318 :" reverse() and sort()
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
319 :let l = ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', [0, 1, 2], 'x8']
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
320 :$put =string(reverse(l))
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
321 :$put =string(reverse(reverse(l)))
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
322 :$put =string(sort(l))
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
323 :$put =string(reverse(sort(l)))
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
324 :$put =string(sort(reverse(sort(l))))
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 148
diff changeset
325 :"
283
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
326 :" splitting a string to a List
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
327 :$put =string(split(' aa bb '))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
328 :$put =string(split(' aa bb ', '\W\+', 0))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
329 :$put =string(split(' aa bb ', '\W\+', 1))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
330 :$put =string(split(' aa bb ', '\W', 1))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
331 :$put =string(split(':aa::bb:', ':', 0))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
332 :$put =string(split(':aa::bb:', ':', 1))
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
333 :$put =string(split('aa,,bb, cc,', ',\s*', 1))
294
1c1cbdc42f75 updated for version 7.0077
vimboss
parents: 283
diff changeset
334 :$put =string(split('abc', '\zs'))
1c1cbdc42f75 updated for version 7.0077
vimboss
parents: 283
diff changeset
335 :$put =string(split('abc', '\zs', 1))
283
a2ff714de3db updated for version 7.0075
vimboss
parents: 164
diff changeset
336 :"
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
337 :" compare recursively linked list and dict
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
338 :let l = [1, 2, 3, 4]
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
339 :let d = {'1': 1, '2': l, '3': 3}
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
340 :let l[1] = d
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
341 :$put =(l == l)
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
342 :$put =(d == d)
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
343 :$put =(l != deepcopy(l))
96cd8222a819 updated for version 7.1a
vimboss
parents: 842
diff changeset
344 :$put =(d != deepcopy(d))
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
345 :endfun
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
346 :call Test(1, 2, [3, 4], {5: 6}) " This may take a while
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
347 :"
1405
b63792dadc23 updated for version 7.1-120
vimboss
parents: 1125
diff changeset
348 :delfunc Test
b63792dadc23 updated for version 7.1-120
vimboss
parents: 1125
diff changeset
349 :unlet dict
b63792dadc23 updated for version 7.1-120
vimboss
parents: 1125
diff changeset
350 :call garbagecollect(1)
b63792dadc23 updated for version 7.1-120
vimboss
parents: 1125
diff changeset
351 :"
119
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
352 :/^start:/,$wq! test.out
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
353 ENDTEST
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
354
e8f07016e34d updated for version 7.0042
vimboss
parents:
diff changeset
355 start: