3618
|
1 Tests for various python features. vim: set ft=vim :
|
|
2
|
|
3 STARTTEST
|
|
4 :so small.vim
|
|
5 :if !has('python3') | e! test.ok | wq! test.out | endif
|
|
6 :py3 import vim
|
|
7 :fun Test()
|
|
8 :let l = []
|
|
9 :py3 l=vim.bindeval('l')
|
|
10 :py3 f=vim.bindeval('function("strlen")')
|
|
11 :" Extending List directly with different types
|
|
12 :py3 l+=[1, "as'd", [1, 2, f, {'a': 1}]]
|
|
13 :$put =string(l)
|
|
14 :$put =string(l[-1])
|
|
15 :try
|
|
16 : $put =string(l[-4])
|
|
17 :catch
|
|
18 : $put =v:exception[:13]
|
|
19 :endtry
|
|
20 :" List assignment
|
|
21 :py3 l[0]=0
|
|
22 :$put =string(l)
|
|
23 :py3 l[-2]=f
|
|
24 :$put =string(l)
|
|
25 :"
|
|
26 :" Extending Dictionary directly with different types
|
|
27 :let d = {}
|
|
28 :py3 d=vim.bindeval('d')
|
|
29 :py3 d['1']='asd'
|
|
30 :py3 d['b']=[1, 2, f]
|
|
31 :py3 d['-1']={'a': 1}
|
|
32 :let dkeys = []
|
|
33 :py3 dk=vim.bindeval('dkeys')
|
|
34 :py3 dkeys=d.keys()
|
|
35 :py3 dkeys.sort()
|
|
36 :py3 dk+=dkeys
|
|
37 :$put =string(dkeys)
|
|
38 :for [key, val] in sort(items(d))
|
|
39 : $put =string(key) . ' : ' . string(val)
|
|
40 : unlet key val
|
|
41 :endfor
|
|
42 :"
|
|
43 :" removing items with del
|
|
44 :py3 del l[2]
|
|
45 :$put =string(l)
|
|
46 :let l = range(8)
|
|
47 :py3 l=vim.bindeval('l')
|
|
48 :try
|
|
49 : py3 del l[:3]
|
|
50 : py3 del l[1:]
|
|
51 :catch
|
|
52 : $put =v:exception
|
|
53 :endtry
|
|
54 :$put =string(l)
|
|
55 :"
|
|
56 :py3 del d['-1']
|
|
57 :$put =string(d)
|
|
58 :"
|
|
59 :" removing items out of range: silently skip items that don't exist
|
|
60 :let l = [0, 1, 2, 3]
|
|
61 :py3 l=vim.bindeval('l')
|
|
62 :" The following two ranges delete nothing as they match empty list:
|
|
63 :py3 del l[2:1]
|
|
64 :$put =string(l)
|
|
65 :py3 del l[2:2]
|
|
66 :$put =string(l)
|
|
67 :py3 del l[2:3]
|
|
68 :$put =string(l)
|
|
69 :let l = [0, 1, 2, 3]
|
|
70 :py3 l=vim.bindeval('l')
|
|
71 :py3 del l[2:4]
|
|
72 :$put =string(l)
|
|
73 :let l = [0, 1, 2, 3]
|
|
74 :py3 l=vim.bindeval('l')
|
|
75 :py3 del l[2:5]
|
|
76 :$put =string(l)
|
|
77 :let l = [0, 1, 2, 3]
|
|
78 :py3 l=vim.bindeval('l')
|
|
79 :py3 del l[2:6]
|
|
80 :$put =string(l)
|
|
81 :let l = [0, 1, 2, 3]
|
|
82 :py3 l=vim.bindeval('l')
|
|
83 :" The following two ranges delete nothing as they match empty list:
|
|
84 :py3 del l[-1:2]
|
|
85 :$put =string(l)
|
|
86 :py3 del l[-2:2]
|
|
87 :$put =string(l)
|
|
88 :py3 del l[-3:2]
|
|
89 :$put =string(l)
|
|
90 :let l = [0, 1, 2, 3]
|
|
91 :py3 l=vim.bindeval('l')
|
|
92 :py3 del l[-4:2]
|
|
93 :$put =string(l)
|
|
94 :let l = [0, 1, 2, 3]
|
|
95 :py3 l=vim.bindeval('l')
|
|
96 :py3 del l[-5:2]
|
|
97 :$put =string(l)
|
|
98 :let l = [0, 1, 2, 3]
|
|
99 :py3 l=vim.bindeval('l')
|
|
100 :py3 del l[-6:2]
|
|
101 :$put =string(l)
|
|
102 :"
|
|
103 :" Slice assignment to a list
|
|
104 :let l = [0, 1, 2, 3]
|
|
105 :py3 l=vim.bindeval('l')
|
|
106 :py3 l[0:0]=['a']
|
|
107 :$put =string(l)
|
|
108 :let l = [0, 1, 2, 3]
|
|
109 :py3 l=vim.bindeval('l')
|
|
110 :py3 l[1:2]=['b']
|
|
111 :$put =string(l)
|
|
112 :let l = [0, 1, 2, 3]
|
|
113 :py3 l=vim.bindeval('l')
|
|
114 :py3 l[2:4]=['c']
|
|
115 :$put =string(l)
|
|
116 :let l = [0, 1, 2, 3]
|
|
117 :py3 l=vim.bindeval('l')
|
|
118 :py3 l[4:4]=['d']
|
|
119 :$put =string(l)
|
|
120 :let l = [0, 1, 2, 3]
|
|
121 :py3 l=vim.bindeval('l')
|
|
122 :py3 l[-1:2]=['e']
|
|
123 :$put =string(l)
|
|
124 :let l = [0, 1, 2, 3]
|
|
125 :py3 l=vim.bindeval('l')
|
|
126 :py3 l[-10:2]=['f']
|
|
127 :$put =string(l)
|
|
128 :let l = [0, 1, 2, 3]
|
|
129 :py3 l=vim.bindeval('l')
|
|
130 :py3 l[2:-10]=['g']
|
|
131 :$put =string(l)
|
|
132 :let l = []
|
|
133 :py3 l=vim.bindeval('l')
|
|
134 :py3 l[0:0]=['h']
|
|
135 :$put =string(l)
|
|
136 :"
|
|
137 :" Locked variables
|
|
138 :let l = [0, 1, 2, 3]
|
|
139 :py3 l=vim.bindeval('l')
|
|
140 :lockvar! l
|
|
141 :py3 l[2]='i'
|
|
142 :$put =string(l)
|
|
143 :unlockvar! l
|
|
144 :"
|
|
145 :" Function calls
|
|
146 :function New(...)
|
|
147 :return ['NewStart']+a:000+['NewEnd']
|
|
148 :endfunction
|
|
149 :function DictNew(...) dict
|
|
150 :return ['DictNewStart']+a:000+['DictNewEnd', self]
|
|
151 :endfunction
|
|
152 :let l=[function('New'), function('DictNew')]
|
|
153 :py3 l=vim.bindeval('l')
|
|
154 :py3 l.extend(list(l[0](1, 2, 3)))
|
|
155 :$put =string(l)
|
|
156 :py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
|
|
157 :$put =string(l)
|
|
158 :py3 l+=[l[0].name]
|
|
159 :$put =string(l)
|
|
160 :try
|
|
161 : py3 l[1](1, 2, 3)
|
|
162 :catch
|
|
163 : $put =v:exception[:13]
|
|
164 :endtry
|
|
165 :delfunction New
|
|
166 :try
|
|
167 : py3 l[0](1, 2, 3)
|
|
168 :catch
|
|
169 : $put =v:exception[:13]
|
|
170 :endtry
|
|
171 :if has('float')
|
|
172 : let l=[0.0]
|
|
173 : py3 l=vim.bindeval('l')
|
|
174 : py3 l.extend([0.0])
|
|
175 : $put =string(l)
|
|
176 :else
|
|
177 : $put ='[0.0, 0.0]'
|
|
178 :endif
|
|
179 :"
|
|
180 :" py3eval()
|
|
181 :let l=py3eval('[0, 1, 2]')
|
|
182 :$put =string(l)
|
|
183 :let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}')
|
|
184 :$put =sort(items(d))
|
|
185 :try
|
|
186 : let undef=py3eval('undefined_name')
|
|
187 :catch
|
|
188 : $put =v:exception[:13]
|
|
189 :endtry
|
|
190 :try
|
|
191 : let vim=py3eval('vim')
|
|
192 :catch
|
|
193 : $put =v:exception[:13]
|
|
194 :endtry
|
|
195 :if has('float')
|
|
196 : let f=py3eval('0.0')
|
|
197 : $put =string(f)
|
|
198 :else
|
|
199 : $put ='0.0'
|
|
200 :endif
|
|
201 :endfun
|
|
202 :"
|
|
203 :call Test()
|
|
204 :"
|
|
205 :delfunc Test
|
|
206 :call garbagecollect(1)
|
|
207 :"
|
|
208 :/^start:/,$wq! test.out
|
|
209 ENDTEST
|
|
210
|
|
211 start:
|