69
|
1 |
"{ Package: 'exept:regression' }"
|
61
|
2 |
|
47
|
3 |
Object subclass:#CompilerTest
|
61
|
4 |
instanceVariableNames:'value'
|
47
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
59
|
7 |
category:'Tests-Regression'
|
47
|
8 |
!
|
|
9 |
|
|
10 |
|
61
|
11 |
!CompilerTest methodsFor:'helpers'!
|
|
12 |
|
|
13 |
value:something
|
|
14 |
value := something
|
|
15 |
! !
|
|
16 |
|
50
|
17 |
!CompilerTest methodsFor:'test - inlined'!
|
|
18 |
|
|
19 |
test_even:arg
|
|
20 |
^ arg even
|
|
21 |
|
|
22 |
"
|
|
23 |
self new test_even:nil
|
|
24 |
self new test_even:123
|
|
25 |
self new test_even:122
|
|
26 |
self new test_even:(100 factorial)
|
|
27 |
"
|
|
28 |
!
|
|
29 |
|
|
30 |
test_isInteger:arg
|
|
31 |
^ arg isInteger
|
|
32 |
|
|
33 |
"
|
|
34 |
self new test_isInteger:nil
|
|
35 |
self new test_isInteger:123
|
|
36 |
self new test_isInteger:(100 factorial)
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
|
40 |
test_isNotInteger:arg
|
|
41 |
^ arg isInteger not
|
|
42 |
|
|
43 |
"
|
|
44 |
self new test_isNotInteger:nil
|
|
45 |
self new test_isNotInteger:123
|
|
46 |
self new test_isNotInteger:(100 factorial)
|
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
test_odd:arg
|
|
51 |
^ arg odd
|
|
52 |
|
|
53 |
"
|
|
54 |
self new test_odd:nil
|
|
55 |
self new test_odd:123
|
|
56 |
self new test_odd:122
|
|
57 |
self new test_odd:(100 factorial)
|
|
58 |
"
|
61
|
59 |
!
|
|
60 |
|
|
61 |
test_size
|
|
62 |
^ value size
|
|
63 |
|
|
64 |
"
|
|
65 |
(self new value:(Array new:2)) test_size
|
|
66 |
(self new value:(OrderedCollection new:2)) test_size
|
|
67 |
"
|
50
|
68 |
! !
|
|
69 |
|
48
|
70 |
!CompilerTest methodsFor:'tests - booleans'!
|
|
71 |
|
50
|
72 |
testAnd:arg1 _:arg2
|
|
73 |
^ arg1 & arg2
|
|
74 |
|
|
75 |
"
|
|
76 |
self new testAnd:true _:true.
|
|
77 |
self new testAnd:true _:false.
|
|
78 |
self new testAnd:false _:true.
|
|
79 |
self new testAnd:false _:false.
|
|
80 |
self new testAnd:false _:nil.
|
|
81 |
self new testAnd:true _:nil.
|
|
82 |
self new testAnd:nil _:false.
|
|
83 |
self new testAnd:nil _:true.
|
|
84 |
self new testAnd:1234 _:true.
|
|
85 |
self new testAnd:1234 _:false.
|
|
86 |
self new testAnd:true _:1234.
|
|
87 |
self new testAnd:false _:1234.
|
|
88 |
"
|
|
89 |
!
|
|
90 |
|
48
|
91 |
testNot1:arg
|
|
92 |
^ arg not
|
|
93 |
|
|
94 |
"
|
49
|
95 |
self new testNot1:true.
|
48
|
96 |
self new testNot1:false.
|
|
97 |
self new testNot1:1234.
|
|
98 |
"
|
|
99 |
!
|
|
100 |
|
|
101 |
testNot2:arg1 _:arg2
|
|
102 |
^ arg1 not & arg2 not
|
|
103 |
|
|
104 |
"
|
|
105 |
self new testNot2:true _:true.
|
|
106 |
self new testNot2:false _:true.
|
|
107 |
self new testNot2:true _:false.
|
|
108 |
self new testNot2:false _:false.
|
|
109 |
|
|
110 |
self new testNot2:false _:1234.
|
|
111 |
self new testNot2:true _:1234.
|
|
112 |
self new testNot2:1234 _:true.
|
|
113 |
self new testNot2:1234 _:false.
|
|
114 |
self new testNot2:1234 _:2345.
|
|
115 |
"
|
50
|
116 |
!
|
|
117 |
|
|
118 |
testOr:arg1 _:arg2
|
|
119 |
^ arg1 | arg2
|
|
120 |
|
|
121 |
"
|
|
122 |
self new testOr:true _:true.
|
|
123 |
self new testOr:true _:false.
|
|
124 |
self new testOr:false _:true.
|
|
125 |
self new testOr:false _:false.
|
|
126 |
self new testOr:false _:nil.
|
|
127 |
self new testOr:true _:nil.
|
|
128 |
self new testOr:nil _:false.
|
|
129 |
self new testOr:nil _:true.
|
|
130 |
self new testOr:1234 _:true.
|
|
131 |
self new testOr:1234 _:false.
|
|
132 |
self new testOr:true _:1234.
|
|
133 |
self new testOr:false _:1234.
|
|
134 |
"
|
48
|
135 |
! !
|
|
136 |
|
62
|
137 |
!CompilerTest methodsFor:'tests - conditions'!
|
|
138 |
|
|
139 |
testIf1:val
|
|
140 |
|x|
|
|
141 |
|
65
|
142 |
x := #foo.
|
|
143 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[1].
|
62
|
144 |
^ x
|
|
145 |
|
|
146 |
"
|
|
147 |
self new testIf1:#CursorRight
|
|
148 |
self new testIf1:#CursorDown
|
64
|
149 |
self new testIf1:#Foo
|
|
150 |
self new testIf1:#CursorUp
|
|
151 |
self new testIf1:nil
|
62
|
152 |
self new testIf1:1
|
|
153 |
"
|
63
|
154 |
!
|
|
155 |
|
|
156 |
testIf2:val
|
|
157 |
|x|
|
|
158 |
|
65
|
159 |
x := #foo.
|
|
160 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1.
|
63
|
161 |
^ x
|
|
162 |
|
|
163 |
"
|
|
164 |
self new testIf2:#CursorRight
|
|
165 |
self new testIf2:#CursorDown
|
|
166 |
self new testIf2:#Foo
|
|
167 |
self new testIf2:#CursorUp
|
|
168 |
self new testIf2:nil
|
|
169 |
self new testIf2:1
|
|
170 |
"
|
65
|
171 |
!
|
|
172 |
|
|
173 |
testIf3:val
|
|
174 |
|x|
|
|
175 |
|
|
176 |
x := #foo.
|
|
177 |
x := (val isInteger) ifTrue:1.
|
|
178 |
^ x
|
|
179 |
|
|
180 |
"
|
|
181 |
self new testIf3:#CursorRight
|
|
182 |
self new testIf3:#CursorDown
|
|
183 |
self new testIf3:#Foo
|
|
184 |
self new testIf3:#CursorUp
|
|
185 |
self new testIf3:nil
|
|
186 |
self new testIf3:1
|
|
187 |
"
|
|
188 |
!
|
|
189 |
|
67
|
190 |
testIf4:val
|
|
191 |
^ val isNil
|
|
192 |
|
|
193 |
"
|
|
194 |
self new testIf4:#CursorRight
|
|
195 |
self new testIf4:1
|
|
196 |
self new testIf4:nil
|
|
197 |
"
|
|
198 |
!
|
|
199 |
|
66
|
200 |
testIf4:val1 with:val2
|
|
201 |
^ (val1 == nil and:[val2 == nil])
|
|
202 |
|
|
203 |
"
|
|
204 |
self new testIf4:#CursorRight with:#CursorDown
|
|
205 |
self new testIf4:#CursorRight with:nil
|
|
206 |
self new testIf4:nil with:#CursorDown
|
|
207 |
self new testIf4:nil with:nil
|
|
208 |
"
|
|
209 |
!
|
|
210 |
|
67
|
211 |
testIf5:val
|
|
212 |
^ val isNil ifTrue:[1]
|
|
213 |
|
|
214 |
"
|
|
215 |
self new testIf5:#CursorRight
|
|
216 |
self new testIf5:1
|
|
217 |
self new testIf5:nil
|
|
218 |
"
|
|
219 |
!
|
|
220 |
|
66
|
221 |
testIf5:val1 with:val2
|
|
222 |
^ (val1 isNil and:[val2 isNil])
|
|
223 |
|
|
224 |
"
|
|
225 |
self new testIf5:#CursorRight with:#CursorDown
|
|
226 |
self new testIf5:#CursorRight with:nil
|
|
227 |
self new testIf5:nil with:#CursorDown
|
|
228 |
self new testIf5:nil with:nil
|
|
229 |
"
|
|
230 |
!
|
|
231 |
|
67
|
232 |
testIf6:val
|
|
233 |
^ val isNil ifTrue:1
|
|
234 |
|
|
235 |
"
|
|
236 |
self new testIf6:#CursorRight
|
|
237 |
self new testIf6:1
|
|
238 |
self new testIf6:nil
|
|
239 |
"
|
|
240 |
!
|
|
241 |
|
68
|
242 |
testIf6b:val
|
|
243 |
val isNil ifTrue:1
|
|
244 |
|
|
245 |
"
|
|
246 |
self new testIf6b:#CursorRight
|
|
247 |
self new testIf6b:1
|
|
248 |
self new testIf6b:nil
|
|
249 |
"
|
|
250 |
!
|
|
251 |
|
|
252 |
testIf6c:val
|
|
253 |
val isNil ifTrue:[1]
|
|
254 |
|
|
255 |
"
|
|
256 |
self new testIf6c:#CursorRight
|
|
257 |
self new testIf6c:1
|
|
258 |
self new testIf6c:nil
|
|
259 |
"
|
|
260 |
!
|
|
261 |
|
|
262 |
testIf6d:val
|
|
263 |
^ val isNil ifTrue:val
|
|
264 |
|
|
265 |
"
|
|
266 |
self new testIf6d:#CursorRight
|
|
267 |
self new testIf6d:1
|
|
268 |
self new testIf6d:nil
|
|
269 |
"
|
|
270 |
!
|
|
271 |
|
|
272 |
testIf6e:val
|
|
273 |
^ val isNil ifFalse:val
|
|
274 |
|
|
275 |
"
|
|
276 |
self new testIf6e:['hello']
|
|
277 |
self new testIf6e:('hello' asValue)
|
|
278 |
self new testIf6e:#CursorRight
|
|
279 |
self new testIf6e:1
|
|
280 |
self new testIf6e:nil
|
|
281 |
"
|
|
282 |
!
|
|
283 |
|
67
|
284 |
testIf7:val
|
|
285 |
^ val ? 1
|
|
286 |
|
|
287 |
"
|
|
288 |
self new testIf7:#CursorRight
|
|
289 |
self new testIf7:1
|
|
290 |
self new testIf7:nil
|
|
291 |
"
|
|
292 |
!
|
|
293 |
|
65
|
294 |
testIfElse1:val
|
|
295 |
|x|
|
|
296 |
|
|
297 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[1] ifFalse:[-1].
|
|
298 |
^ x
|
|
299 |
|
|
300 |
"
|
|
301 |
self new testIfElse1:#CursorRight
|
|
302 |
self new testIfElse1:#CursorDown
|
|
303 |
self new testIfElse1:#Foo
|
|
304 |
self new testIfElse1:#CursorUp
|
|
305 |
self new testIfElse1:nil
|
|
306 |
self new testIfElse1:1
|
|
307 |
"
|
|
308 |
!
|
|
309 |
|
|
310 |
testIfElse2:val
|
|
311 |
|x|
|
|
312 |
|
|
313 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1 ifFalse:-1.
|
|
314 |
^ x
|
|
315 |
|
|
316 |
"
|
|
317 |
self new testIfElse2:#CursorRight
|
|
318 |
self new testIfElse2:#CursorDown
|
|
319 |
self new testIfElse2:#Foo
|
|
320 |
self new testIfElse2:#CursorUp
|
|
321 |
self new testIfElse2:nil
|
|
322 |
self new testIfElse2:1
|
|
323 |
"
|
|
324 |
!
|
|
325 |
|
|
326 |
testIfElse3:val
|
|
327 |
|x|
|
|
328 |
|
|
329 |
x := (val == #CursorRight or:[val isInteger]) ifTrue:1 ifFalse:-1.
|
|
330 |
^ x
|
|
331 |
|
|
332 |
"
|
|
333 |
self new testIfElse3:#CursorRight
|
|
334 |
self new testIfElse3:#CursorDown
|
|
335 |
self new testIfElse3:#Foo
|
|
336 |
self new testIfElse3:#CursorUp
|
|
337 |
self new testIfElse3:nil
|
|
338 |
self new testIfElse3:1
|
|
339 |
"
|
|
340 |
!
|
|
341 |
|
|
342 |
testIfElse4:val
|
|
343 |
|x|
|
|
344 |
|
|
345 |
x := #foo.
|
|
346 |
x := (val isInteger) ifTrue:1 ifFalse:-1.
|
|
347 |
^ x
|
|
348 |
|
|
349 |
"
|
|
350 |
self new testIfElse4:#CursorRight
|
|
351 |
self new testIfElse4:#CursorDown
|
|
352 |
self new testIfElse4:#Foo
|
|
353 |
self new testIfElse4:#CursorUp
|
|
354 |
self new testIfElse4:nil
|
|
355 |
self new testIfElse4:1
|
|
356 |
"
|
68
|
357 |
!
|
|
358 |
|
|
359 |
testIfElse5:val
|
|
360 |
|x|
|
|
361 |
|
|
362 |
x := #foo.
|
|
363 |
x := val ifNil:1 ifNotNil:-1.
|
|
364 |
^ x
|
|
365 |
|
|
366 |
"
|
|
367 |
self new testIfElse5:#CursorUp
|
|
368 |
self new testIfElse5:nil
|
|
369 |
self new testIfElse5:1
|
|
370 |
"
|
|
371 |
!
|
|
372 |
|
|
373 |
testIfElse6:val
|
|
374 |
|x|
|
|
375 |
|
|
376 |
x := #foo.
|
|
377 |
x := val ifNil:[1] ifNotNil:[-1].
|
|
378 |
^ x
|
|
379 |
|
|
380 |
"
|
|
381 |
self new testIfElse6:#CursorUp
|
|
382 |
self new testIfElse6:nil
|
|
383 |
self new testIfElse6:1
|
|
384 |
"
|
|
385 |
!
|
|
386 |
|
|
387 |
testIfElse7:val with:val1 with:val2
|
|
388 |
|x|
|
|
389 |
|
|
390 |
x := #foo.
|
|
391 |
x := val ifNil:val1 ifNotNil:val2.
|
|
392 |
^ x
|
|
393 |
|
|
394 |
"
|
|
395 |
self new testIfElse7:#CursorUp with:1 with:2
|
|
396 |
self new testIfElse7:nil with:1 with:2
|
|
397 |
self new testIfElse7:1 with:1 with:2
|
|
398 |
"
|
62
|
399 |
! !
|
|
400 |
|
47
|
401 |
!CompilerTest methodsFor:'tests - constant folding'!
|
|
402 |
|
|
403 |
testFloat_pi
|
|
404 |
^ Float pi
|
|
405 |
!
|
|
406 |
|
|
407 |
testFloat_unity
|
|
408 |
^ Float unity
|
|
409 |
!
|
|
410 |
|
|
411 |
testFloat_zero
|
|
412 |
^ Float zero
|
|
413 |
!
|
|
414 |
|
|
415 |
testSmalltalk_if_else_isSmalltalkX
|
|
416 |
Smalltalk isSmalltalkX ifTrue:[
|
59
|
417 |
^ 'yes'
|
47
|
418 |
] ifFalse:[
|
59
|
419 |
^ 'no'
|
47
|
420 |
]
|
|
421 |
!
|
|
422 |
|
|
423 |
testSmalltalk_if_else_isVisualWorks
|
|
424 |
Smalltalk isVisualWorks ifTrue:[
|
59
|
425 |
^ 'yes'
|
47
|
426 |
] ifFalse:[
|
59
|
427 |
^ 'no'
|
47
|
428 |
]
|
|
429 |
!
|
|
430 |
|
|
431 |
testSmalltalk_if_isSmalltalkX
|
|
432 |
Smalltalk isSmalltalkX ifTrue:[
|
59
|
433 |
^ 'yes'
|
47
|
434 |
].
|
|
435 |
^ 'no'
|
|
436 |
!
|
|
437 |
|
|
438 |
testSmalltalk_if_isSqueak
|
|
439 |
Smalltalk isSqueak ifTrue:[
|
59
|
440 |
^ 'yes'
|
47
|
441 |
].
|
|
442 |
^ 'no'
|
|
443 |
!
|
|
444 |
|
|
445 |
testSmalltalk_if_isVisualWorks
|
|
446 |
Smalltalk isVisualWorks ifTrue:[
|
59
|
447 |
^ 'yes'
|
47
|
448 |
].
|
|
449 |
^ 'no'
|
|
450 |
!
|
|
451 |
|
|
452 |
testSmalltalk_isSmalltalkX
|
|
453 |
^ Smalltalk isSmalltalkX
|
|
454 |
!
|
|
455 |
|
|
456 |
testSmalltalk_isSqueak
|
|
457 |
^ Smalltalk isSqueak
|
|
458 |
!
|
|
459 |
|
|
460 |
testSmalltalk_isVisualAge
|
|
461 |
^ Smalltalk isVisualAge
|
|
462 |
!
|
|
463 |
|
|
464 |
testSmalltalk_isVisualWorks
|
|
465 |
^ Smalltalk isVisualWorks
|
|
466 |
!
|
|
467 |
|
|
468 |
testUnaryFolding
|
|
469 |
self testFloat_pi ~= (Float perform:#pi) ifTrue:[self halt].
|
|
470 |
self testFloat_unity ~= (Float perform:#unity) ifTrue:[self halt].
|
|
471 |
self testFloat_zero ~= (Float perform:#zero) ifTrue:[self halt].
|
|
472 |
|
|
473 |
self testSmalltalk_isSmalltalkX ~= (Smalltalk perform:#isSmalltalkX) ifTrue:[self halt].
|
|
474 |
self testSmalltalk_isSqueak ~= (Smalltalk perform:#isSqueak) ifTrue:[self halt].
|
|
475 |
self testSmalltalk_isVisualWorks ~= (Smalltalk perform:#isVisualWorks) ifTrue:[self halt].
|
|
476 |
self testSmalltalk_isVisualAge ~= (Smalltalk perform:#isVisualAge) ifTrue:[self halt].
|
|
477 |
|
|
478 |
"
|
|
479 |
self basicNew testUnaryFolding
|
|
480 |
"
|
|
481 |
! !
|
|
482 |
|
|
483 |
!CompilerTest class methodsFor:'documentation'!
|
|
484 |
|
|
485 |
version
|
|
486 |
^ '$Header$'
|
|
487 |
! !
|