]> git.madduck.net Git - etc/vim.git/blob - tests/expression.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Improve test coverage a bit
[etc/vim.git] / tests / expression.py
1 ...
2 'some_string'
3 b'\\xa3'
4 Name
5 None
6 True
7 False
8 1
9 1.0
10 1j
11 True or False
12 True or False or None
13 True and False
14 True and False and None
15 (Name1 and Name2) or Name3
16 Name1 and Name2 or Name3
17 Name1 or (Name2 and Name3)
18 Name1 or Name2 and Name3
19 (Name1 and Name2) or (Name3 and Name4)
20 Name1 and Name2 or Name3 and Name4
21 Name1 or (Name2 and Name3) or Name4
22 Name1 or Name2 and Name3 or Name4
23 v1 << 2
24 1 >> v2
25 1 % finished
26 1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
27 ((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
28 not great
29 ~great
30 +value
31 -1
32 ~int and not v1 ^ 123 + v2 | True
33 (~int) and (not ((v1 ^ (123 + v2)) | True))
34 flags & ~ select.EPOLLIN and waiters.write_task is not None
35 lambda arg: None
36 lambda a=True: a
37 lambda a, b, c=True: a
38 lambda a, b, c=True, *, d=(1 << v2), e='str': a
39 lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
40 1 if True else 2
41 str or None if True else str or bytes or None
42 (str or None) if True else (str or bytes or None)
43 str or None if (1 if True else 2) else str or bytes or None
44 (str or None) if (1 if True else 2) else (str or bytes or None)
45 {'2.7': dead, '3.7': (long_live or die_hard)}
46 {'2.7': dead, '3.7': (long_live or die_hard), **{'3.6': verygood}}
47 {**a, **b, **c}
48 {'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')}
49 ({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None
50 ()
51 (1,)
52 (1, 2)
53 (1, 2, 3)
54 []
55 [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
56 [1, 2, 3,]
57 {i for i in (1, 2, 3)}
58 {(i ** 2) for i in (1, 2, 3)}
59 {(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))}
60 {((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)}
61 [i for i in (1, 2, 3)]
62 [(i ** 2) for i in (1, 2, 3)]
63 [(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))]
64 [((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
65 {i: 0 for i in (1, 2, 3)}
66 {i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
67 {a: b * 2 for a, b in dictionary.items()}
68 {a: b * -2 for a, b in dictionary.items()}
69 {k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension}
70 Python3 > Python2 > COBOL
71 Life is Life
72 call()
73 call(arg)
74 call(kwarg='hey')
75 call(arg, kwarg='hey')
76 call(arg, another, kwarg='hey', **kwargs)
77 call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs)  # note: no trailing comma pre-3.6
78 call(*gidgets[:2])
79 call(**self.screen_kwargs)
80 lukasz.langa.pl
81 call.me(maybe)
82 1 .real
83 1.0 .real
84 ....__class__
85 list[str]
86 dict[str, int]
87 tuple[str, ...]
88 tuple[str, int, float, dict[str, int],]
89 very_long_variable_name_filters: t.List[
90     t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
91 ]
92 slice[0]
93 slice[0:1]
94 slice[0:1:2]
95 slice[:]
96 slice[:-1]
97 slice[1:]
98 slice[::-1]
99 slice[d::d + 1]
100 slice[:c, c - 1]
101 numpy[:, 0:1]
102 numpy[:, :-1]
103 numpy[0, :]
104 numpy[:, i]
105 numpy[0, :2]
106 numpy[:N, 0]
107 numpy[:2, :4]
108 numpy[2:4, 1:5]
109 numpy[4:, 2:]
110 numpy[:, (0, 1, 2, 5)]
111 numpy[0, [0]]
112 numpy[:, [i]]
113 numpy[1:c + 1, c]
114 numpy[-(c + 1):, d]
115 numpy[:, l[-2]]
116 numpy[:, ::-1]
117 numpy[np.newaxis, :]
118 (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
119 {'2.7': dead, '3.7': long_live or die_hard}
120 {'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}
121 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
122 (SomeName)
123 SomeName
124 (Good, Bad, Ugly)
125 (i for i in (1, 2, 3))
126 ((i ** 2) for i in (1, 2, 3))
127 ((i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c')))
128 (((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
129 (*starred)
130 a = (1,)
131 b = 1,
132 c = 1
133 d = (1,) + a + (2,)
134 e = (1,).count(1)
135 what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove)
136 what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove)
137 result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all()
138
139 def gen():
140     yield from outside_of_generator
141     a = (yield)
142
143 async def f():
144     await some.complicated[0].call(with_args=(True or (1 is not 1)))
145
146 if (
147     threading.current_thread() != threading.main_thread() and
148     threading.current_thread() != threading.main_thread() or
149     signal.getsignal(signal.SIGINT) != signal.default_int_handler
150 ):
151     return True
152 if (
153     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
154     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
155 ):
156     return True
157 if (
158     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &
159     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
160 ):
161     return True
162 if (
163     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
164     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
165 ):
166     return True
167 if (
168     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
169     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
170 ):
171     return True
172 if (
173     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
174     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
175 ):
176     return True
177 if (
178     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /
179     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
180 ):
181     return True
182 last_call()
183 # standalone comment at ENDMARKER
184
185
186 # output
187
188
189 ...
190 "some_string"
191 b"\\xa3"
192 Name
193 None
194 True
195 False
196 1
197 1.0
198 1j
199 True or False
200 True or False or None
201 True and False
202 True and False and None
203 (Name1 and Name2) or Name3
204 Name1 and Name2 or Name3
205 Name1 or (Name2 and Name3)
206 Name1 or Name2 and Name3
207 (Name1 and Name2) or (Name3 and Name4)
208 Name1 and Name2 or Name3 and Name4
209 Name1 or (Name2 and Name3) or Name4
210 Name1 or Name2 and Name3 or Name4
211 v1 << 2
212 1 >> v2
213 1 % finished
214 1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
215 ((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
216 not great
217 ~great
218 +value
219 -1
220 ~int and not v1 ^ 123 + v2 | True
221 (~int) and (not ((v1 ^ (123 + v2)) | True))
222 flags & ~select.EPOLLIN and waiters.write_task is not None
223 lambda arg: None
224 lambda a=True: a
225 lambda a, b, c=True: a
226 lambda a, b, c=True, *, d=(1 << v2), e="str": a
227 lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
228 1 if True else 2
229 str or None if True else str or bytes or None
230 (str or None) if True else (str or bytes or None)
231 str or None if (1 if True else 2) else str or bytes or None
232 (str or None) if (1 if True else 2) else (str or bytes or None)
233 {"2.7": dead, "3.7": (long_live or die_hard)}
234 {"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
235 {**a, **b, **c}
236 {"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
237 ({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
238 ()
239 (1,)
240 (1, 2)
241 (1, 2, 3)
242 []
243 [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
244 [1, 2, 3]
245 {i for i in (1, 2, 3)}
246 {(i ** 2) for i in (1, 2, 3)}
247 {(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))}
248 {((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)}
249 [i for i in (1, 2, 3)]
250 [(i ** 2) for i in (1, 2, 3)]
251 [(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))]
252 [((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
253 {i: 0 for i in (1, 2, 3)}
254 {i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
255 {a: b * 2 for a, b in dictionary.items()}
256 {a: b * -2 for a, b in dictionary.items()}
257 {
258     k: v
259     for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
260 }
261 Python3 > Python2 > COBOL
262 Life is Life
263 call()
264 call(arg)
265 call(kwarg="hey")
266 call(arg, kwarg="hey")
267 call(arg, another, kwarg="hey", **kwargs)
268 call(
269     this_is_a_very_long_variable_which_will_force_a_delimiter_split,
270     arg,
271     another,
272     kwarg="hey",
273     **kwargs
274 )  # note: no trailing comma pre-3.6
275 call(*gidgets[:2])
276 call(**self.screen_kwargs)
277 lukasz.langa.pl
278 call.me(maybe)
279 1 .real
280 1.0 .real
281 ....__class__
282 list[str]
283 dict[str, int]
284 tuple[str, ...]
285 tuple[str, int, float, dict[str, int]]
286 very_long_variable_name_filters: t.List[
287     t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
288 ]
289 slice[0]
290 slice[0:1]
291 slice[0:1:2]
292 slice[:]
293 slice[:-1]
294 slice[1:]
295 slice[::-1]
296 slice[d::d + 1]
297 slice[:c, c - 1]
298 numpy[:, 0:1]
299 numpy[:, :-1]
300 numpy[0, :]
301 numpy[:, i]
302 numpy[0, :2]
303 numpy[:N, 0]
304 numpy[:2, :4]
305 numpy[2:4, 1:5]
306 numpy[4:, 2:]
307 numpy[:, (0, 1, 2, 5)]
308 numpy[0, [0]]
309 numpy[:, [i]]
310 numpy[1:c + 1, c]
311 numpy[-(c + 1):, d]
312 numpy[:, l[-2]]
313 numpy[:, ::-1]
314 numpy[np.newaxis, :]
315 (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
316 {"2.7": dead, "3.7": long_live or die_hard}
317 {"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
318 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
319 (SomeName)
320 SomeName
321 (Good, Bad, Ugly)
322 (i for i in (1, 2, 3))
323 ((i ** 2) for i in (1, 2, 3))
324 ((i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
325 (((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
326 (*starred)
327 a = (1,)
328 b = 1,
329 c = 1
330 d = (1,) + a + (2,)
331 e = (1,).count(1)
332 what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
333     vars_to_remove
334 )
335 what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
336     vars_to_remove
337 )
338 result = session.query(models.Customer.id).filter(
339     models.Customer.account_id == account_id, models.Customer.email == email_address
340 ).order_by(
341     models.Customer.id.asc()
342 ).all()
343
344
345 def gen():
346     yield from outside_of_generator
347
348     a = (yield)
349
350
351 async def f():
352     await some.complicated[0].call(with_args=(True or (1 is not 1)))
353
354
355 if (
356     threading.current_thread() != threading.main_thread()
357     and threading.current_thread() != threading.main_thread()
358     or signal.getsignal(signal.SIGINT) != signal.default_int_handler
359 ):
360     return True
361
362 if (
363     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
364     | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
365 ):
366     return True
367
368 if (
369     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
370     & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
371 ):
372     return True
373
374 if (
375     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
376     + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
377 ):
378     return True
379
380 if (
381     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
382     - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
383 ):
384     return True
385
386 if (
387     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
388     * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
389 ):
390     return True
391
392 if (
393     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
394     / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
395 ):
396     return True
397
398 last_call()
399 # standalone comment at ENDMARKER