-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathirbuild-dunders.test
More file actions
215 lines (194 loc) · 3.42 KB
/
irbuild-dunders.test
File metadata and controls
215 lines (194 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Test cases for (some) dunder methods
[case testDundersLen]
class C:
def __len__(self) -> int:
return 2
def f(c: C) -> int:
return len(c)
[out]
def C.__len__(self):
self :: __main__.C
L0:
return 4
def f(c):
c :: __main__.C
r0 :: int
r1 :: bit
r2 :: bool
L0:
r0 = c.__len__()
r1 = int_ge r0, 0
if r1 goto L2 else goto L1 :: bool
L1:
r2 = raise ValueError('__len__() should return >= 0')
unreachable
L2:
return r0
[case testDundersSetItem]
class C:
def __setitem__(self, key: int, value: int) -> None:
pass
def f(c: C) -> None:
c[3] = 4
[out]
def C.__setitem__(self, key, value):
self :: __main__.C
key, value :: int
L0:
return 1
def f(c):
c :: __main__.C
r0 :: None
L0:
r0 = c.__setitem__(6, 8)
return 1
[case testDundersContains]
from typing import Any
class C:
def __contains__(self, x: int) -> bool:
return False
def f(c: C) -> bool:
return 7 in c
def g(c: C) -> bool:
return 7 not in c
class D:
def __contains__(self, x: int) -> Any:
return 'x'
def h(d: D) -> bool:
return 7 not in d
[out]
def C.__contains__(self, x):
self :: __main__.C
x :: int
L0:
return 0
def f(c):
c :: __main__.C
r0 :: bool
L0:
r0 = c.__contains__(14)
return r0
def g(c):
c :: __main__.C
r0, r1 :: bool
L0:
r0 = c.__contains__(14)
r1 = r0 ^ 1
return r1
def D.__contains__(self, x):
self :: __main__.D
x :: int
r0 :: str
L0:
r0 = 'x'
return r0
def h(d):
d :: __main__.D
r0 :: object
r1 :: i32
r2 :: bit
r3, r4 :: bool
L0:
r0 = d.__contains__(14)
r1 = PyObject_IsTrue(r0)
r2 = r1 >= 0 :: signed
r3 = truncate r1: i32 to builtins.bool
r4 = r3 ^ 1
return r4
[case testDundersDelItem]
class C:
def __delitem__(self, x: int) -> None:
pass
def f(c: C) -> None:
del c[5]
[out]
def C.__delitem__(self, x):
self :: __main__.C
x :: int
L0:
return 1
def f(c):
c :: __main__.C
r0 :: None
L0:
r0 = c.__delitem__(10)
return 1
[case testDundersUnary]
class C:
def __neg__(self) -> int:
return 1
def __invert__(self) -> int:
return 2
def __int__(self) -> int:
return 3
def __float__(self) -> float:
return 4.0
def __pos__(self) -> int:
return 5
def __abs__(self) -> int:
return 6
def __bool__(self) -> bool:
return False
def __complex__(self) -> complex:
return 7j
def f(c: C) -> None:
-c
~c
int(c)
float(c)
+c
abs(c)
bool(c)
complex(c)
[out]
def C.__neg__(self):
self :: __main__.C
L0:
return 2
def C.__invert__(self):
self :: __main__.C
L0:
return 4
def C.__int__(self):
self :: __main__.C
L0:
return 6
def C.__float__(self):
self :: __main__.C
L0:
return 4.0
def C.__pos__(self):
self :: __main__.C
L0:
return 10
def C.__abs__(self):
self :: __main__.C
L0:
return 12
def C.__bool__(self):
self :: __main__.C
L0:
return 0
def C.__complex__(self):
self :: __main__.C
r0 :: object
L0:
r0 = 7j
return r0
def f(c):
c :: __main__.C
r0, r1, r2 :: int
r3 :: float
r4, r5 :: int
r6 :: bool
r7 :: object
L0:
r0 = c.__neg__()
r1 = c.__invert__()
r2 = c.__int__()
r3 = c.__float__()
r4 = c.__pos__()
r5 = c.__abs__()
r6 = c.__bool__()
r7 = c.__complex__()
return 1