author | Claus Gittinger <cg@exept.de> |
Tue, 24 Aug 2010 12:53:07 +0200 | |
changeset 568 | 2d5d66196b5e |
parent 329 | f016dcc761f4 |
child 569 | e16012b59e29 |
permissions | -rw-r--r-- |
69 | 1 |
"{ Package: 'exept:regression' }" |
61 | 2 |
|
70 | 3 |
"{ NameSpace: RegressionTests }" |
4 |
||
113 | 5 |
TestCase subclass:#CompilerTest |
61 | 6 |
instanceVariableNames:'value' |
47 | 7 |
classVariableNames:'' |
8 |
poolDictionaries:'' |
|
181 | 9 |
category:'tests-Regression' |
47 | 10 |
! |
11 |
||
188 | 12 |
Object subclass:#DummyClass |
13 |
instanceVariableNames:'applicationModel service request' |
|
14 |
classVariableNames:'' |
|
15 |
poolDictionaries:'' |
|
16 |
privateIn:CompilerTest |
|
17 |
! |
|
18 |
||
47 | 19 |
|
328 | 20 |
!CompilerTest class methodsFor:'others'! |
21 |
||
22 |
foo:arg |
|
23 |
^ arg |
|
24 |
ifTrue:[^ 1] |
|
25 |
ifFalse:[2] |
|
26 |
! ! |
|
27 |
||
88 | 28 |
!CompilerTest class methodsFor:'tests - constants'! |
29 |
||
30 |
test_int1024 |
|
31 |
^ 1024 |
|
32 |
||
33 |
" |
|
34 |
self test_int1024 |
|
35 |
" |
|
36 |
||
37 |
! |
|
38 |
||
39 |
test_int1048576 |
|
40 |
^ 1048576 |
|
41 |
! |
|
42 |
||
43 |
test_int128 |
|
44 |
^ 128 |
|
45 |
||
46 |
" |
|
47 |
self test_int128 |
|
48 |
" |
|
49 |
! |
|
50 |
||
51 |
test_int131072 |
|
52 |
^ 131072 |
|
53 |
! |
|
54 |
||
55 |
test_int16384 |
|
56 |
^ 16384 |
|
57 |
||
58 |
" |
|
59 |
self test_int16384 |
|
60 |
" |
|
61 |
||
62 |
! |
|
63 |
||
64 |
test_int2048 |
|
65 |
^ 2048 |
|
66 |
||
67 |
" |
|
68 |
self test_int2048 |
|
69 |
" |
|
70 |
||
71 |
! |
|
72 |
||
73 |
test_int2097152 |
|
74 |
^ 2097152 |
|
75 |
! |
|
76 |
||
77 |
test_int256 |
|
78 |
^ 256 |
|
79 |
||
80 |
" |
|
81 |
self test_int256 |
|
82 |
" |
|
83 |
||
84 |
! |
|
85 |
||
86 |
test_int262144 |
|
87 |
^ 262144 |
|
88 |
! |
|
89 |
||
90 |
test_int32768 |
|
91 |
^ 32768 |
|
92 |
||
93 |
" |
|
94 |
self test_int32768 |
|
95 |
" |
|
96 |
||
97 |
! |
|
98 |
||
99 |
test_int4096 |
|
100 |
^ 4096 |
|
101 |
||
102 |
" |
|
103 |
self test_int4096 |
|
104 |
" |
|
105 |
||
106 |
! |
|
107 |
||
108 |
test_int512 |
|
109 |
^ 512 |
|
110 |
||
111 |
" |
|
112 |
self test_int512 |
|
113 |
" |
|
114 |
||
115 |
! |
|
116 |
||
117 |
test_int524288 |
|
118 |
^ 524288 |
|
119 |
! |
|
120 |
||
121 |
test_int65536 |
|
122 |
^ 65536 |
|
123 |
||
124 |
" |
|
125 |
self test_int65536 |
|
126 |
" |
|
127 |
||
128 |
! |
|
129 |
||
130 |
test_int8192 |
|
131 |
^ 8192 |
|
132 |
||
133 |
" |
|
134 |
self test_int8192 |
|
135 |
" |
|
136 |
||
137 |
! |
|
138 |
||
139 |
test_intM128 |
|
140 |
^ -128 |
|
141 |
! ! |
|
142 |
||
77 | 143 |
!CompilerTest class methodsFor:'tests argument passing'! |
144 |
||
145 |
ret0 |
|
146 |
^ 0 |
|
147 |
||
148 |
" |
|
149 |
self ret0 |
|
78 | 150 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self ret0] ] |
77 | 151 |
" |
152 |
! |
|
153 |
||
154 |
ret1 |
|
155 |
^ 1 |
|
156 |
||
157 |
" |
|
158 |
self ret1 |
|
78 | 159 |
1000000 timesRepeat:[self ret1] |
160 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self ret1] ] |
|
161 |
" |
|
162 |
! |
|
163 |
||
164 |
retArg1:arg |
|
165 |
^ arg |
|
166 |
||
167 |
" |
|
168 |
self retArg1:1 |
|
169 |
1000000 timesRepeat:[self retArg1:1] |
|
170 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg1:1] ] |
|
171 |
" |
|
172 |
! |
|
173 |
||
174 |
retArg2:arg1 _:arg2 |
|
175 |
^ arg2 |
|
176 |
||
177 |
" |
|
178 |
self retArg2:1 _:2 |
|
179 |
1000000 timesRepeat:[self retArg2:1 _:2] |
|
180 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg2:1 _:2] ] |
|
181 |
" |
|
182 |
! |
|
183 |
||
184 |
retArg3:arg1 _:arg2 _:arg3 |
|
185 |
^ arg3 |
|
186 |
||
187 |
" |
|
188 |
self retArg3:1 _:2 _:3 |
|
189 |
1000000 timesRepeat:[self retArg3:1 _:2 _:3] |
|
190 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg3:1 _:2 _:3] ] |
|
191 |
" |
|
192 |
! |
|
193 |
||
194 |
retArg4:arg1 _:arg2 _:arg3 _:arg4 |
|
195 |
^ arg4 |
|
196 |
||
197 |
" |
|
198 |
self retArg4:1 _:2 _:3 _:4 |
|
199 |
1000000 timesRepeat:[self retArg4:1 _:2 _:3 _:4] |
|
200 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg4:1 _:2 _:3 _:4] ] |
|
201 |
" |
|
202 |
! |
|
203 |
||
79 | 204 |
retArg5:arg1 _:arg2 _:arg3 _:arg4 _:arg5 |
205 |
^ arg5 |
|
206 |
||
207 |
" |
|
208 |
self retArg5:1 _:2 _:3 _:4 _:5 |
|
209 |
1000000 timesRepeat:[self retArg5:1 _:2 _:3 _:4 _:5] |
|
210 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg5:1 _:2 _:3 _:4 _:5] ] |
|
211 |
" |
|
212 |
! |
|
213 |
||
78 | 214 |
retLiteral1 |
215 |
^ 'hello' |
|
216 |
||
217 |
" |
|
218 |
self retLiteral1 |
|
219 |
1000000 timesRepeat:[self retLiteral1] |
|
220 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retLiteral1] ] |
|
77 | 221 |
" |
222 |
! |
|
223 |
||
224 |
retM1 |
|
225 |
^ -1 |
|
226 |
||
227 |
" |
|
228 |
self retM1 |
|
78 | 229 |
1000000 timesRepeat:[self retM1] |
230 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retM1] ] |
|
77 | 231 |
" |
232 |
! |
|
233 |
||
234 |
retSelf |
|
235 |
^ self |
|
236 |
||
237 |
" |
|
238 |
self retSelf |
|
78 | 239 |
1000000 timesRepeat:[self retSelf] |
240 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retSelf] ] |
|
77 | 241 |
" |
242 |
! ! |
|
243 |
||
61 | 244 |
!CompilerTest methodsFor:'helpers'! |
245 |
||
568 | 246 |
callEnsureWith2Returns |
247 |
[ |
|
248 |
^ false |
|
249 |
] ensure:[ |
|
250 |
^ true |
|
251 |
]. |
|
252 |
^ nil |
|
253 |
||
254 |
"Created: / 24-08-2010 / 12:51:50 / cg" |
|
255 |
! |
|
256 |
||
81 | 257 |
size |
258 |
^ 1 |
|
259 |
! |
|
260 |
||
61 | 261 |
value:something |
262 |
value := something |
|
263 |
! ! |
|
264 |
||
328 | 265 |
!CompilerTest methodsFor:'others'! |
266 |
||
267 |
foo:arg |
|
268 |
^ arg |
|
269 |
ifTrue:[1] |
|
270 |
ifFalse:[2] |
|
271 |
! ! |
|
272 |
||
48 | 273 |
!CompilerTest methodsFor:'tests - booleans'! |
274 |
||
113 | 275 |
_testAnd:arg1 _:arg2 |
50 | 276 |
^ arg1 & arg2 |
277 |
||
278 |
" |
|
113 | 279 |
self new _testAnd:true _:true. |
280 |
self new _testAnd:true _:false. |
|
281 |
self new _testAnd:false _:true. |
|
282 |
self new _testAnd:false _:false. |
|
283 |
self new _testAnd:false _:nil. |
|
284 |
self new _testAnd:true _:nil. |
|
285 |
self new _testAnd:nil _:false. |
|
286 |
self new _testAnd:nil _:true. |
|
287 |
self new _testAnd:1234 _:true. |
|
288 |
self new _testAnd:1234 _:false. |
|
289 |
self new _testAnd:true _:1234. |
|
290 |
self new _testAnd:false _:1234. |
|
291 |
" |
|
292 |
! |
|
293 |
||
294 |
_testNot1:arg |
|
295 |
^ arg not |
|
296 |
||
297 |
" |
|
298 |
self new _testNot1:true. |
|
299 |
self new _testNot1:false. |
|
300 |
self new _testNot1:1234. |
|
50 | 301 |
" |
302 |
! |
|
303 |
||
113 | 304 |
_testNot2:arg1 _:arg2 |
305 |
^ arg1 not & arg2 not |
|
48 | 306 |
|
307 |
" |
|
113 | 308 |
self new _testNot2:true _:true. |
309 |
self new _testNot2:false _:true. |
|
310 |
self new _testNot2:true _:false. |
|
311 |
self new _testNot2:false _:false. |
|
312 |
||
313 |
self new _testNot2:false _:1234. |
|
314 |
self new _testNot2:true _:1234. |
|
315 |
self new _testNot2:1234 _:true. |
|
316 |
self new _testNot2:1234 _:false. |
|
317 |
self new _testNot2:1234 _:2345. |
|
318 |
" |
|
319 |
! |
|
320 |
||
321 |
_testNot3:arg1 _:arg2 |
|
322 |
^ arg1 not | arg2 not |
|
323 |
||
324 |
" |
|
325 |
self new _testNot3:true _:true. |
|
326 |
self new _testNot3:false _:true. |
|
327 |
self new _testNot3:true _:false. |
|
328 |
self new _testNot3:false _:false. |
|
329 |
||
330 |
self new _testNot3:false _:1234. |
|
331 |
self new _testNot3:true _:1234. |
|
332 |
self new _testNot3:1234 _:true. |
|
333 |
self new _testNot3:1234 _:false. |
|
334 |
self new _testNot3:1234 _:2345. |
|
48 | 335 |
" |
336 |
! |
|
337 |
||
113 | 338 |
_testOr:arg1 _:arg2 |
339 |
^ arg1 | arg2 |
|
48 | 340 |
|
341 |
" |
|
113 | 342 |
self new _testOr:true _:true. |
343 |
self new _testOr:true _:false. |
|
344 |
self new _testOr:false _:true. |
|
345 |
self new _testOr:false _:false. |
|
346 |
self new _testOr:false _:nil. |
|
347 |
self new _testOr:true _:nil. |
|
348 |
self new _testOr:nil _:false. |
|
349 |
self new _testOr:nil _:true. |
|
350 |
self new _testOr:1234 _:true. |
|
351 |
self new _testOr:1234 _:false. |
|
352 |
self new _testOr:true _:1234. |
|
353 |
self new _testOr:false _:1234. |
|
354 |
" |
|
355 |
! |
|
48 | 356 |
|
113 | 357 |
testAnd |
358 |
self assert:( ( self _testAnd:true _:true ) == true ). |
|
359 |
self assert:( ( self _testAnd:true _:false ) == false ). |
|
360 |
self assert:( ( self _testAnd:false _:true ) == false ). |
|
361 |
self assert:( ( self _testAnd:false _:false ) == false ). |
|
362 |
||
363 |
self assert:( ( self _testAnd:false _:nil ) == false ). |
|
364 |
self assert:( ( self _testAnd:true _:nil ) == nil ). |
|
365 |
self assert:( ( self _testAnd:false _:1234 ) == false ). |
|
366 |
self assert:( ( self _testAnd:true _:1234 ) == 1234 ). |
|
367 |
self should:[ self _testAnd:nil _:false ] raise:Error. |
|
368 |
self should:[ self _testAnd:nil _:true ] raise:Error. |
|
369 |
self should:[ self _testAnd:1234 _:false ] raise:Error. |
|
370 |
self should:[ self _testAnd:1234 _:true ] raise:Error. |
|
371 |
||
372 |
" |
|
373 |
self new testAnd |
|
48 | 374 |
" |
50 | 375 |
! |
376 |
||
113 | 377 |
testNot |
378 |
self assert:( ( self _testNot1:true ) == false ). |
|
379 |
self assert:( ( self _testNot1:false ) == true ). |
|
380 |
||
381 |
self should:[ self _testNot1:nil ] raise:Error. |
|
382 |
self should:[ self _testNot1:1234 ] raise:Error. |
|
383 |
||
384 |
||
385 |
self assert:( ( self _testNot2:true _:true) == false ). |
|
386 |
self assert:( ( self _testNot2:false _:true) == false ). |
|
387 |
self assert:( ( self _testNot2:true _:false) == false ). |
|
388 |
self assert:( ( self _testNot2:false _:false) == true ). |
|
389 |
||
390 |
self should:[ self _testNot2:false _:1234] raise:Error. |
|
391 |
self should:[ self _testNot2:true _:1234] raise:Error. |
|
392 |
self should:[ self _testNot2:1234 _:false] raise:Error. |
|
393 |
self should:[ self _testNot2:1234 _:true] raise:Error. |
|
394 |
self should:[ self _testNot2:1234 _:1234] raise:Error. |
|
395 |
self should:[ self _testNot2:nil _:false] raise:Error. |
|
396 |
self should:[ self _testNot2:nil _:true] raise:Error. |
|
397 |
self should:[ self _testNot2:nil _:1234] raise:Error. |
|
398 |
||
399 |
self assert:( ( self _testNot3:true _:true) == false ). |
|
400 |
self assert:( ( self _testNot3:false _:true) == true ). |
|
401 |
self assert:( ( self _testNot3:true _:false) == true ). |
|
402 |
self assert:( ( self _testNot3:false _:false) == true ). |
|
403 |
||
404 |
self should:[ self _testNot3:false _:1234] raise:Error. |
|
405 |
self should:[ self _testNot3:true _:1234] raise:Error. |
|
406 |
self should:[ self _testNot3:1234 _:false] raise:Error. |
|
407 |
self should:[ self _testNot3:1234 _:true] raise:Error. |
|
408 |
self should:[ self _testNot3:1234 _:1234] raise:Error. |
|
409 |
self should:[ self _testNot3:nil _:false] raise:Error. |
|
410 |
self should:[ self _testNot3:nil _:true] raise:Error. |
|
411 |
self should:[ self _testNot3:nil _:1234] raise:Error. |
|
50 | 412 |
|
413 |
" |
|
113 | 414 |
self new testNot |
415 |
" |
|
416 |
! |
|
417 |
||
418 |
testOr |
|
419 |
self assert:( ( self _testOr:true _:true ) == true ). |
|
420 |
self assert:( ( self _testOr:true _:false ) == true ). |
|
421 |
self assert:( ( self _testOr:false _:true ) == true ). |
|
422 |
self assert:( ( self _testOr:false _:false ) == false ). |
|
423 |
||
424 |
self assert:( ( self _testOr:false _:nil ) == nil ). |
|
425 |
self assert:( ( self _testOr:true _:nil ) == true ). |
|
426 |
self assert:( ( self _testOr:false _:1234 ) == 1234 ). |
|
427 |
self assert:( ( self _testOr:true _:1234 ) == true ). |
|
428 |
self should:[ self _testOr:nil _:false ] raise:Error. |
|
429 |
self should:[ self _testOr:nil _:true ] raise:Error. |
|
430 |
self should:[ self _testOr:1234 _:false ] raise:Error. |
|
431 |
self should:[ self _testOr:1234 _:true ] raise:Error. |
|
432 |
||
433 |
" |
|
434 |
self new testOr |
|
50 | 435 |
" |
48 | 436 |
! ! |
437 |
||
62 | 438 |
!CompilerTest methodsFor:'tests - conditions'! |
439 |
||
113 | 440 |
_testIf1:val |
62 | 441 |
|x| |
442 |
||
65 | 443 |
x := #foo. |
444 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[1]. |
|
62 | 445 |
^ x |
446 |
||
447 |
" |
|
113 | 448 |
self new _testIf1:#CursorRight |
449 |
self new _testIf1:#CursorDown |
|
450 |
self new _testIf1:#Foo |
|
451 |
self new _testIf1:#CursorUp |
|
452 |
self new _testIf1:nil |
|
453 |
self new _testIf1:1 |
|
62 | 454 |
" |
63 | 455 |
! |
456 |
||
113 | 457 |
_testIf2:val |
63 | 458 |
|x| |
459 |
||
65 | 460 |
x := #foo. |
461 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1. |
|
63 | 462 |
^ x |
463 |
||
464 |
" |
|
113 | 465 |
self new _testIf2:#CursorRight |
466 |
self new _testIf2:#CursorDown |
|
467 |
self new _testIf2:#Foo |
|
468 |
self new _testIf2:#CursorUp |
|
469 |
self new _testIf2:nil |
|
470 |
self new _testIf2:1 |
|
63 | 471 |
" |
65 | 472 |
! |
473 |
||
113 | 474 |
_testIf3:val |
65 | 475 |
|x| |
476 |
||
477 |
x := #foo. |
|
113 | 478 |
x := val isInteger ifTrue:1. |
65 | 479 |
^ x |
480 |
||
481 |
" |
|
113 | 482 |
self new _testIf3:#CursorRight |
483 |
self new _testIf3:#CursorDown |
|
484 |
self new _testIf3:#Foo |
|
485 |
self new _testIf3:#CursorUp |
|
486 |
self new _testIf3:nil |
|
487 |
self new _testIf3:1 |
|
65 | 488 |
" |
489 |
! |
|
490 |
||
113 | 491 |
_testIf4:val |
67 | 492 |
^ val isNil |
493 |
||
494 |
" |
|
113 | 495 |
self new _testIf4:#CursorRight |
496 |
self new _testIf4:1 |
|
497 |
self new _testIf4:nil |
|
67 | 498 |
" |
499 |
! |
|
500 |
||
113 | 501 |
_testIf4:val1 with:val2 |
502 |
^ val1 == nil and:[val2 == nil] |
|
66 | 503 |
|
504 |
" |
|
113 | 505 |
self new _testIf4:#CursorRight with:#CursorDown |
506 |
self new _testIf4:#CursorRight with:nil |
|
507 |
self new _testIf4:nil with:#CursorDown |
|
508 |
self new _testIf4:nil with:nil |
|
66 | 509 |
" |
510 |
! |
|
511 |
||
113 | 512 |
_testIf5:val |
513 |
^ val isNil ifTrue:[ |
|
514 |
1 |
|
515 |
] |
|
67 | 516 |
|
517 |
" |
|
113 | 518 |
self new _testIf5:#CursorRight |
519 |
self new _testIf5:1 |
|
520 |
self new _testIf5:nil |
|
67 | 521 |
" |
522 |
! |
|
523 |
||
113 | 524 |
_testIf5:val1 with:val2 |
525 |
^ val1 isNil and:[val2 isNil] |
|
66 | 526 |
|
527 |
" |
|
113 | 528 |
self new _testIf5:#CursorRight with:#CursorDown |
529 |
self new _testIf5:#CursorRight with:nil |
|
530 |
self new _testIf5:nil with:#CursorDown |
|
531 |
self new _testIf5:nil with:nil |
|
66 | 532 |
" |
533 |
! |
|
534 |
||
113 | 535 |
_testIf6:val |
67 | 536 |
^ val isNil ifTrue:1 |
537 |
||
538 |
" |
|
113 | 539 |
self new _testIf6:#CursorRight |
540 |
self new _testIf6:1 |
|
541 |
self new _testIf6:nil |
|
67 | 542 |
" |
543 |
! |
|
544 |
||
113 | 545 |
_testIf6b:val |
68 | 546 |
val isNil ifTrue:1 |
547 |
||
548 |
" |
|
113 | 549 |
self new _testIf6b:#CursorRight |
550 |
self new _testIf6b:1 |
|
551 |
self new _testIf6b:nil |
|
68 | 552 |
" |
553 |
! |
|
554 |
||
113 | 555 |
_testIf6c:val |
556 |
val isNil ifTrue:[ |
|
557 |
1 |
|
68 | 558 |
|
113 | 559 |
" |
560 |
self new _testIf6c:#CursorRight |
|
561 |
self new _testIf6c:1 |
|
562 |
self new _testIf6c:nil |
|
563 |
" |
|
564 |
] |
|
68 | 565 |
! |
566 |
||
113 | 567 |
_testIf6d:val |
68 | 568 |
^ val isNil ifTrue:val |
569 |
||
570 |
" |
|
113 | 571 |
self new _testIf6d:#CursorRight |
572 |
self new _testIf6d:1 |
|
573 |
self new _testIf6d:nil |
|
68 | 574 |
" |
575 |
! |
|
576 |
||
113 | 577 |
_testIf6e:val |
68 | 578 |
^ val isNil ifFalse:val |
579 |
||
580 |
" |
|
113 | 581 |
self new _testIf6e:['hello'] |
582 |
self new _testIf6e:('hello' asValue) |
|
583 |
self new _testIf6e:#CursorRight |
|
584 |
self new _testIf6e:1 |
|
585 |
self new _testIf6e:nil |
|
68 | 586 |
" |
587 |
! |
|
588 |
||
113 | 589 |
_testIf7:val |
67 | 590 |
^ val ? 1 |
591 |
||
592 |
" |
|
113 | 593 |
self new _testIf7:#CursorRight |
594 |
self new _testIf7:1 |
|
595 |
self new _testIf7:nil |
|
67 | 596 |
" |
597 |
! |
|
598 |
||
113 | 599 |
_testIfElse1:val |
65 | 600 |
|x| |
601 |
||
113 | 602 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[ |
603 |
1 |
|
604 |
] ifFalse:[-1]. |
|
65 | 605 |
^ x |
606 |
||
607 |
" |
|
113 | 608 |
self new _testIfElse1:#CursorRight |
609 |
self new _testIfElse1:#CursorDown |
|
610 |
self new _testIfElse1:#Foo |
|
611 |
self new _testIfElse1:#CursorUp |
|
612 |
self new _testIfElse1:nil |
|
613 |
self new _testIfElse1:1 |
|
65 | 614 |
" |
615 |
! |
|
616 |
||
113 | 617 |
_testIfElse2:val |
65 | 618 |
|x| |
619 |
||
620 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1 ifFalse:-1. |
|
621 |
^ x |
|
622 |
||
623 |
" |
|
113 | 624 |
self new _testIfElse2:#CursorRight |
625 |
self new _testIfElse2:#CursorDown |
|
626 |
self new _testIfElse2:#Foo |
|
627 |
self new _testIfElse2:#CursorUp |
|
628 |
self new _testIfElse2:nil |
|
629 |
self new _testIfElse2:1 |
|
65 | 630 |
" |
631 |
! |
|
632 |
||
113 | 633 |
_testIfElse3:val |
65 | 634 |
|x| |
635 |
||
636 |
x := (val == #CursorRight or:[val isInteger]) ifTrue:1 ifFalse:-1. |
|
637 |
^ x |
|
638 |
||
639 |
" |
|
113 | 640 |
self new _testIfElse3:#CursorRight |
641 |
self new _testIfElse3:#CursorDown |
|
642 |
self new _testIfElse3:#Foo |
|
643 |
self new _testIfElse3:#CursorUp |
|
644 |
self new _testIfElse3:nil |
|
645 |
self new _testIfElse3:1 |
|
65 | 646 |
" |
647 |
! |
|
648 |
||
113 | 649 |
_testIfElse4:val |
65 | 650 |
|x| |
651 |
||
652 |
x := #foo. |
|
113 | 653 |
x := val isInteger ifTrue:1 ifFalse:-1. |
65 | 654 |
^ x |
655 |
||
656 |
" |
|
113 | 657 |
self new _testIfElse4:#CursorRight |
658 |
self new _testIfElse4:#CursorDown |
|
659 |
self new _testIfElse4:#Foo |
|
660 |
self new _testIfElse4:#CursorUp |
|
661 |
self new _testIfElse4:nil |
|
662 |
self new _testIfElse4:1 |
|
65 | 663 |
" |
68 | 664 |
! |
665 |
||
113 | 666 |
_testIfElse5:val |
68 | 667 |
|x| |
668 |
||
669 |
x := #foo. |
|
670 |
x := val ifNil:1 ifNotNil:-1. |
|
671 |
^ x |
|
672 |
||
673 |
" |
|
113 | 674 |
self new _testIfElse5:#CursorUp |
675 |
self new _testIfElse5:nil |
|
676 |
self new _testIfElse5:1 |
|
68 | 677 |
" |
678 |
! |
|
679 |
||
113 | 680 |
_testIfElse6:val |
68 | 681 |
|x| |
682 |
||
683 |
x := #foo. |
|
684 |
x := val ifNil:[1] ifNotNil:[-1]. |
|
685 |
^ x |
|
686 |
||
687 |
" |
|
113 | 688 |
self new _testIfElse6:#CursorUp |
689 |
self new _testIfElse6:nil |
|
690 |
self new _testIfElse6:1 |
|
68 | 691 |
" |
692 |
! |
|
693 |
||
113 | 694 |
_testIfElse7:val with:val1 with:val2 |
68 | 695 |
|x| |
696 |
||
697 |
x := #foo. |
|
698 |
x := val ifNil:val1 ifNotNil:val2. |
|
699 |
^ x |
|
700 |
||
701 |
" |
|
113 | 702 |
self new _testIfElse7:#CursorUp with:1 with:2 |
703 |
self new _testIfElse7:nil with:1 with:2 |
|
704 |
self new _testIfElse7:1 with:1 with:2 |
|
705 |
" |
|
706 |
! |
|
707 |
||
708 |
testIf |
|
709 |
self assert:(self _testIf1:#CursorRight) == 1. |
|
710 |
self assert:(self _testIf1:#CursorDown) == 1. |
|
711 |
self assert:(self _testIf1:#Foo) == nil. |
|
712 |
self assert:(self _testIf1:#CursorUp) == nil. |
|
713 |
self assert:(self _testIf1:nil) == nil. |
|
714 |
self assert:(self _testIf1:1) == nil. |
|
715 |
||
716 |
self assert:(self _testIf2:#CursorRight) == 1. |
|
717 |
self assert:(self _testIf2:#CursorDown) == 1. |
|
718 |
self assert:(self _testIf2:#Foo) == nil. |
|
719 |
self assert:(self _testIf2:#CursorUp) == nil. |
|
720 |
self assert:(self _testIf2:nil) == nil. |
|
721 |
self assert:(self _testIf2:1) == nil. |
|
722 |
||
723 |
self assert:(self _testIf3:#CursorRight) == nil. |
|
724 |
self assert:(self _testIf3:#CursorDown) == nil. |
|
725 |
self assert:(self _testIf3:#Foo) == nil. |
|
726 |
self assert:(self _testIf3:#CursorUp) == nil. |
|
727 |
self assert:(self _testIf3:nil) == nil. |
|
728 |
self assert:(self _testIf3:1) == 1. |
|
729 |
||
730 |
self assert:(self _testIf4:#CursorRight) == false. |
|
731 |
self assert:(self _testIf4:nil) == true. |
|
732 |
self assert:(self _testIf4:1) == false. |
|
733 |
||
734 |
self assert:(self _testIf4:#CursorRight with:#CursorDown) == false. |
|
735 |
self assert:(self _testIf4:#CursorRight with:nil) == false. |
|
736 |
self assert:(self _testIf4:nil with:#CursorDown) == false. |
|
737 |
self assert:(self _testIf4:nil with:nil) == true. |
|
738 |
||
739 |
self assert:(self _testIf5:#CursorRight) == nil. |
|
740 |
self assert:(self _testIf5:nil) == 1. |
|
741 |
self assert:(self _testIf5:1) == nil. |
|
742 |
||
743 |
self assert:(self _testIf5:#CursorRight with:#CursorDown) == false. |
|
744 |
self assert:(self _testIf5:#CursorRight with:nil) == false. |
|
745 |
self assert:(self _testIf5:nil with:#CursorDown) == false. |
|
746 |
self assert:(self _testIf5:nil with:nil) == true. |
|
747 |
||
748 |
self assert:(self _testIf6:#CursorRight) == nil. |
|
749 |
self assert:(self _testIf6:nil) == 1. |
|
750 |
self assert:(self _testIf6:1) == nil. |
|
751 |
self assert:(self _testIf6d:#CursorRight) == nil. |
|
752 |
self assert:(self _testIf6d:nil) == nil. |
|
753 |
self assert:(self _testIf6d:1) == nil. |
|
754 |
self assert:(self _testIf6e:#CursorRight) == #CursorRight. |
|
755 |
self assert:(self _testIf6e:nil) == nil. |
|
756 |
self assert:(self _testIf6e:1) == 1. |
|
757 |
self assert:(self _testIf7:#CursorRight) == #CursorRight. |
|
758 |
self assert:(self _testIf7:nil) == 1. |
|
759 |
self assert:(self _testIf7:1) == 1. |
|
760 |
||
761 |
self assert:(self _testIfElse1:#CursorRight) == 1. |
|
762 |
self assert:(self _testIfElse1:#CursorDown) == 1. |
|
763 |
self assert:(self _testIfElse1:#Foo) == -1. |
|
764 |
self assert:(self _testIfElse1:#CursorUp) == -1. |
|
765 |
self assert:(self _testIfElse1:nil) == -1. |
|
766 |
self assert:(self _testIfElse1:1) == -1. |
|
767 |
||
768 |
self assert:(self _testIfElse2:#CursorRight) == 1. |
|
769 |
self assert:(self _testIfElse2:#CursorDown) == 1. |
|
770 |
self assert:(self _testIfElse2:#Foo) == -1. |
|
771 |
self assert:(self _testIfElse2:#CursorUp) == -1. |
|
772 |
self assert:(self _testIfElse2:nil) == -1. |
|
773 |
self assert:(self _testIfElse2:1) == -1. |
|
774 |
||
775 |
self assert:(self _testIfElse3:#CursorRight) == 1. |
|
776 |
self assert:(self _testIfElse3:#CursorDown) == -1. |
|
777 |
self assert:(self _testIfElse3:#Foo) == -1. |
|
778 |
self assert:(self _testIfElse3:#CursorUp) == -1. |
|
779 |
self assert:(self _testIfElse3:nil) == -1. |
|
780 |
self assert:(self _testIfElse3:1) == 1. |
|
781 |
||
782 |
self assert:(self _testIfElse4:#CursorRight) == -1. |
|
783 |
self assert:(self _testIfElse4:#CursorDown) == -1. |
|
784 |
self assert:(self _testIfElse4:#Foo) == -1. |
|
785 |
self assert:(self _testIfElse4:#CursorUp) == -1. |
|
786 |
self assert:(self _testIfElse4:nil) == -1. |
|
787 |
self assert:(self _testIfElse4:1) == 1. |
|
788 |
||
789 |
self assert:(self _testIfElse5:#CursorUp) == -1. |
|
790 |
self assert:(self _testIfElse5:nil) == 1. |
|
791 |
self assert:(self _testIfElse5:1) == -1. |
|
792 |
||
793 |
self assert:(self _testIfElse6:#CursorUp) == -1. |
|
794 |
self assert:(self _testIfElse6:nil) == 1. |
|
795 |
self assert:(self _testIfElse6:1) == -1. |
|
796 |
||
797 |
self assert:(self _testIfElse7:#CursorUp with:1 with:2) == 2. |
|
798 |
self assert:(self _testIfElse7:nil with:1 with:2) == 1. |
|
799 |
self assert:(self _testIfElse7:1 with:1 with:2) == 2. |
|
800 |
||
801 |
" |
|
802 |
self basicNew testIf |
|
68 | 803 |
" |
62 | 804 |
! ! |
805 |
||
47 | 806 |
!CompilerTest methodsFor:'tests - constant folding'! |
807 |
||
113 | 808 |
_testFloat_pi |
47 | 809 |
^ Float pi |
810 |
! |
|
811 |
||
113 | 812 |
_testFloat_unity |
47 | 813 |
^ Float unity |
814 |
! |
|
815 |
||
113 | 816 |
_testFloat_zero |
47 | 817 |
^ Float zero |
818 |
! |
|
819 |
||
113 | 820 |
_testSmalltalk_if_else_isSmalltalkX |
47 | 821 |
Smalltalk isSmalltalkX ifTrue:[ |
113 | 822 |
^ 'yes' |
823 |
] ifFalse:[^ 'no'] |
|
47 | 824 |
! |
825 |
||
113 | 826 |
_testSmalltalk_if_else_isVisualWorks |
47 | 827 |
Smalltalk isVisualWorks ifTrue:[ |
113 | 828 |
^ 'yes' |
829 |
] ifFalse:[^ 'no'] |
|
47 | 830 |
! |
831 |
||
113 | 832 |
_testSmalltalk_if_isSmalltalkX |
47 | 833 |
Smalltalk isSmalltalkX ifTrue:[ |
113 | 834 |
^ 'yes' |
835 |
]. |
|
836 |
^ 'no' |
|
837 |
! |
|
838 |
||
839 |
_testSmalltalk_if_isSqueak |
|
840 |
Smalltalk isSqueak ifTrue:[ |
|
841 |
^ 'yes' |
|
47 | 842 |
]. |
843 |
^ 'no' |
|
844 |
! |
|
845 |
||
113 | 846 |
_testSmalltalk_if_isVisualWorks |
47 | 847 |
Smalltalk isVisualWorks ifTrue:[ |
113 | 848 |
^ 'yes' |
47 | 849 |
]. |
850 |
^ 'no' |
|
851 |
! |
|
852 |
||
113 | 853 |
_testSmalltalk_isSmalltalkX |
47 | 854 |
^ Smalltalk isSmalltalkX |
855 |
! |
|
856 |
||
113 | 857 |
_testSmalltalk_isSqueak |
47 | 858 |
^ Smalltalk isSqueak |
859 |
! |
|
860 |
||
113 | 861 |
_testSmalltalk_isVisualAge |
47 | 862 |
^ Smalltalk isVisualAge |
863 |
! |
|
864 |
||
113 | 865 |
_testSmalltalk_isVisualWorks |
47 | 866 |
^ Smalltalk isVisualWorks |
867 |
! |
|
868 |
||
113 | 869 |
_testUnaryFolding |
870 |
self _testFloat_pi ~= (Float perform:#pi) ifTrue:[ |
|
871 |
self halt |
|
872 |
]. |
|
873 |
self _testFloat_unity ~= (Float perform:#unity) ifTrue:[ |
|
874 |
self halt |
|
875 |
]. |
|
876 |
self _testFloat_zero ~= (Float perform:#zero) ifTrue:[ |
|
877 |
self halt |
|
878 |
]. |
|
879 |
self _testSmalltalk_isSmalltalkX ~= (Smalltalk perform:#isSmalltalkX) ifTrue:[ |
|
880 |
self halt |
|
881 |
]. |
|
882 |
self _testSmalltalk_isSqueak ~= (Smalltalk perform:#isSqueak) ifTrue:[ |
|
883 |
self halt |
|
884 |
]. |
|
885 |
self _testSmalltalk_isVisualWorks ~= (Smalltalk perform:#isVisualWorks) ifTrue:[ |
|
886 |
self halt |
|
887 |
]. |
|
888 |
self _testSmalltalk_isVisualAge ~= (Smalltalk perform:#isVisualAge) ifTrue:[ |
|
889 |
self halt |
|
890 |
] |
|
47 | 891 |
|
892 |
" |
|
113 | 893 |
self basicNew _testUnaryFolding |
47 | 894 |
" |
895 |
! ! |
|
896 |
||
568 | 897 |
!CompilerTest methodsFor:'tests - context setup'! |
898 |
||
899 |
_testContextA |
|
900 |
ObjectMemory dumpObject:thisContext |
|
901 |
||
902 |
" |
|
903 |
self new _testContextA |
|
904 |
" |
|
905 |
! |
|
906 |
||
907 |
_testContextB |
|
908 |
ObjectMemory dumpObject:thisContext sender |
|
909 |
||
910 |
" |
|
911 |
self new _testContextB |
|
912 |
" |
|
913 |
! |
|
914 |
||
915 |
_testContextC |
|
916 |
thisContext fullPrintAll |
|
917 |
||
918 |
" |
|
919 |
self new _testContextC |
|
920 |
" |
|
921 |
! |
|
922 |
||
923 |
_testContextD |
|
924 |
self _testContextB |
|
925 |
||
926 |
" |
|
927 |
self new _testContextD |
|
928 |
" |
|
929 |
! |
|
930 |
||
931 |
_testContextE |
|
932 |
^ thisContext sender |
|
933 |
||
934 |
" |
|
935 |
self new _testContextE |
|
936 |
" |
|
937 |
! |
|
938 |
||
939 |
_testContextF |
|
940 |
^ self _testContextE |
|
941 |
||
942 |
" |
|
943 |
self new _testContextF |
|
944 |
" |
|
945 |
! |
|
946 |
||
947 |
_testSend0 |
|
948 |
^ 9999 |
|
949 |
! |
|
950 |
||
951 |
_testSend0B:arg |
|
952 |
^ arg |
|
953 |
! |
|
954 |
||
955 |
_testSend1 |
|
956 |
^ self _testSend0 |
|
957 |
||
958 |
" |
|
959 |
self new testSend1 |
|
960 |
" |
|
961 |
! |
|
962 |
||
963 |
_testSend1B |
|
964 |
^ self _testSend0B:1234 |
|
965 |
||
966 |
" |
|
967 |
self new testSend1B |
|
968 |
" |
|
969 |
! |
|
970 |
||
971 |
_testSend1C:arg |
|
972 |
^ self _testSend0B:arg |
|
973 |
||
974 |
" |
|
975 |
self new testSend1C:9998 |
|
976 |
" |
|
977 |
! |
|
978 |
||
979 |
_testSend2 |
|
980 |
self _testContextB |
|
981 |
||
982 |
" |
|
983 |
self new testSend2 |
|
984 |
" |
|
985 |
! |
|
986 |
||
987 |
_testSend3 |
|
988 |
self _testContextC |
|
989 |
||
990 |
" |
|
991 |
self new testSend3 |
|
992 |
" |
|
993 |
! |
|
994 |
||
995 |
retArgWithFrameA:arg |
|
996 |
|a b c| |
|
997 |
||
998 |
a := 0. |
|
999 |
b := 1. |
|
1000 |
c := 2. |
|
1001 |
^ arg |
|
1002 |
||
1003 |
" |
|
1004 |
self new retArgWithFrameA:999 |
|
1005 |
" |
|
1006 |
! |
|
1007 |
||
1008 |
retArgWithFrameB:arg |
|
1009 |
|a b c| |
|
1010 |
||
1011 |
a := 0. |
|
1012 |
b := 1. |
|
1013 |
c := 2. |
|
1014 |
self retSelf. |
|
1015 |
||
1016 |
^ arg |
|
1017 |
||
1018 |
" |
|
1019 |
self new retArgWithFrameB:9999 |
|
1020 |
" |
|
1021 |
! |
|
1022 |
||
1023 |
retLocal |
|
1024 |
|a| |
|
1025 |
||
1026 |
a := 0. |
|
1027 |
^ a |
|
1028 |
||
1029 |
" |
|
1030 |
self new retLocal |
|
1031 |
1000000 timesRepeat:[self new retInstVar] |
|
1032 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1033 |
" |
|
1034 |
||
1035 |
" |
|
1036 |
|i| |
|
1037 |
||
1038 |
i := self new. |
|
1039 |
i instVarAt:1 put:12345. |
|
1040 |
i retInstVar |
|
1041 |
" |
|
1042 |
||
1043 |
" |
|
1044 |
|i| |
|
1045 |
i := self new. |
|
1046 |
i instVarAt:1 put:12345. |
|
1047 |
1000000 timesRepeat:[i retInstVar] |
|
1048 |
" |
|
1049 |
||
1050 |
" |
|
1051 |
|i| |
|
1052 |
i := self new. |
|
1053 |
i instVarAt:1 put:12345. |
|
1054 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1055 |
" |
|
1056 |
||
1057 |
||
1058 |
! |
|
1059 |
||
1060 |
retLocalB |
|
1061 |
|a b c| |
|
1062 |
||
1063 |
a := 0. |
|
1064 |
b := 1. |
|
1065 |
c := 2. |
|
1066 |
^ a |
|
1067 |
||
1068 |
" |
|
1069 |
self new retLocalB |
|
1070 |
1000000 timesRepeat:[self new retLocalB] |
|
1071 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1072 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retLocalB] ] |
|
1073 |
" |
|
1074 |
||
1075 |
" |
|
1076 |
|i| |
|
1077 |
||
1078 |
i := self new. |
|
1079 |
i instVarAt:1 put:12345. |
|
1080 |
i retInstVar |
|
1081 |
" |
|
1082 |
||
1083 |
" |
|
1084 |
|i| |
|
1085 |
i := self new. |
|
1086 |
i instVarAt:1 put:12345. |
|
1087 |
1000000 timesRepeat:[i retInstVar] |
|
1088 |
" |
|
1089 |
||
1090 |
" |
|
1091 |
|i| |
|
1092 |
i := self new. |
|
1093 |
i instVarAt:1 put:12345. |
|
1094 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1095 |
" |
|
1096 |
||
1097 |
||
1098 |
! |
|
1099 |
||
1100 |
retLocalC |
|
1101 |
|a b c| |
|
1102 |
||
1103 |
a := 0. |
|
1104 |
b := 1. |
|
1105 |
c := 2. |
|
1106 |
^ b |
|
1107 |
||
1108 |
" |
|
1109 |
self new retLocalC |
|
1110 |
1000000 timesRepeat:[self new retInstVar] |
|
1111 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1112 |
" |
|
1113 |
||
1114 |
" |
|
1115 |
|i| |
|
1116 |
||
1117 |
i := self new. |
|
1118 |
i instVarAt:1 put:12345. |
|
1119 |
i retInstVar |
|
1120 |
" |
|
1121 |
||
1122 |
" |
|
1123 |
|i| |
|
1124 |
i := self new. |
|
1125 |
i instVarAt:1 put:12345. |
|
1126 |
1000000 timesRepeat:[i retInstVar] |
|
1127 |
" |
|
1128 |
||
1129 |
" |
|
1130 |
|i| |
|
1131 |
i := self new. |
|
1132 |
i instVarAt:1 put:12345. |
|
1133 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1134 |
" |
|
1135 |
||
1136 |
||
1137 |
! |
|
1138 |
||
1139 |
retLocalD |
|
1140 |
|a b c| |
|
1141 |
||
1142 |
a := 0. |
|
1143 |
b := 1. |
|
1144 |
c := 2. |
|
1145 |
^ c |
|
1146 |
||
1147 |
" |
|
1148 |
self new retLocalD |
|
1149 |
1000000 timesRepeat:[self new retInstVar] |
|
1150 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1151 |
" |
|
1152 |
||
1153 |
" |
|
1154 |
|i| |
|
1155 |
||
1156 |
i := self new. |
|
1157 |
i instVarAt:1 put:12345. |
|
1158 |
i retInstVar |
|
1159 |
" |
|
1160 |
||
1161 |
" |
|
1162 |
|i| |
|
1163 |
i := self new. |
|
1164 |
i instVarAt:1 put:12345. |
|
1165 |
1000000 timesRepeat:[i retInstVar] |
|
1166 |
" |
|
1167 |
||
1168 |
" |
|
1169 |
|i| |
|
1170 |
i := self new. |
|
1171 |
i instVarAt:1 put:12345. |
|
1172 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1173 |
" |
|
1174 |
||
1175 |
||
1176 |
! |
|
1177 |
||
1178 |
retLocalE |
|
1179 |
|a b c| |
|
1180 |
||
1181 |
a := 0. |
|
1182 |
b := 1. |
|
1183 |
c := 2. |
|
1184 |
^ self |
|
1185 |
||
1186 |
" |
|
1187 |
self new retLocalE |
|
1188 |
1000000 timesRepeat:[self new retInstVar] |
|
1189 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1190 |
" |
|
1191 |
||
1192 |
" |
|
1193 |
|i| |
|
1194 |
||
1195 |
i := self new. |
|
1196 |
i instVarAt:1 put:12345. |
|
1197 |
i retInstVar |
|
1198 |
" |
|
1199 |
||
1200 |
" |
|
1201 |
|i| |
|
1202 |
i := self new. |
|
1203 |
i instVarAt:1 put:12345. |
|
1204 |
1000000 timesRepeat:[i retInstVar] |
|
1205 |
" |
|
1206 |
||
1207 |
" |
|
1208 |
|i| |
|
1209 |
i := self new. |
|
1210 |
i instVarAt:1 put:12345. |
|
1211 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1212 |
" |
|
1213 |
||
1214 |
||
1215 |
! |
|
1216 |
||
1217 |
retLocalF |
|
1218 |
|a b c| |
|
1219 |
||
1220 |
a := 0. |
|
1221 |
b := 1. |
|
1222 |
c := 2. |
|
1223 |
self retSelf. |
|
1224 |
||
1225 |
^ a |
|
1226 |
||
1227 |
" |
|
1228 |
self new retLocalF |
|
1229 |
" |
|
1230 |
||
1231 |
||
1232 |
||
1233 |
! |
|
1234 |
||
1235 |
retLocalG |
|
1236 |
|a b c| |
|
1237 |
||
1238 |
a := 0. |
|
1239 |
b := 1. |
|
1240 |
c := 2. |
|
1241 |
self retSelf. |
|
1242 |
||
1243 |
^ b |
|
1244 |
||
1245 |
" |
|
1246 |
self new retLocalG |
|
1247 |
" |
|
1248 |
||
1249 |
||
1250 |
||
1251 |
! |
|
1252 |
||
1253 |
retLocalH |
|
1254 |
|a b c| |
|
1255 |
||
1256 |
a := 0. |
|
1257 |
b := 1. |
|
1258 |
c := 2. |
|
1259 |
self retSelf. |
|
1260 |
||
1261 |
^ c |
|
1262 |
||
1263 |
" |
|
1264 |
self new retLocalH |
|
1265 |
" |
|
1266 |
||
1267 |
||
1268 |
||
1269 |
! |
|
1270 |
||
1271 |
retSelf |
|
1272 |
||
1273 |
||
1274 |
! ! |
|
1275 |
||
1276 |
!CompilerTest methodsFor:'tests - entry'! |
|
1277 |
||
1278 |
ilcMissCheck |
|
1279 |
||
1280 |
||
1281 |
||
1282 |
" |
|
1283 |
(Array with:self new with:nil) do:[:el | el size printCR.]. |
|
1284 |
" |
|
1285 |
||
1286 |
||
1287 |
||
1288 |
! ! |
|
1289 |
||
87 | 1290 |
!CompilerTest methodsFor:'tests - inlined'! |
1291 |
||
113 | 1292 |
_test_even:arg |
87 | 1293 |
^ arg even |
1294 |
||
1295 |
" |
|
113 | 1296 |
self new _test_even:nil |
1297 |
self new _test_even:123 |
|
1298 |
self new _test_even:122 |
|
1299 |
self new _test_even:(100 factorial) |
|
87 | 1300 |
" |
1301 |
! |
|
1302 |
||
113 | 1303 |
_test_isInteger:arg |
87 | 1304 |
^ arg isInteger |
1305 |
||
1306 |
" |
|
113 | 1307 |
self new _test_isInteger:nil |
1308 |
self new _test_isInteger:123 |
|
1309 |
self new _test_isInteger:(100 factorial) |
|
87 | 1310 |
" |
1311 |
! |
|
1312 |
||
113 | 1313 |
_test_isNotInteger:arg |
87 | 1314 |
^ arg isInteger not |
1315 |
||
1316 |
" |
|
113 | 1317 |
self new _test_isNotInteger:nil |
1318 |
self new _test_isNotInteger:123 |
|
1319 |
self new _test_isNotInteger:(100 factorial) |
|
87 | 1320 |
" |
1321 |
! |
|
1322 |
||
113 | 1323 |
_test_max1:arg1 _:arg2 |
87 | 1324 |
^ arg1 max:arg2 |
1325 |
||
1326 |
" |
|
113 | 1327 |
self new _test_max1:nil _:nil |
1328 |
self new _test_max1:1 _:nil |
|
1329 |
self new _test_max1:nil _:1 |
|
1330 |
self new _test_max1:1 _:2 |
|
1331 |
self new _test_max1:2 _:1 |
|
1332 |
||
1333 |
self new _test_max1:1.0 _:nil |
|
1334 |
self new _test_max1:nil _:1.0 |
|
1335 |
self new _test_max1:1.0 _:2.0 |
|
1336 |
self new _test_max1:2.0 _:1.0 |
|
1337 |
||
1338 |
self new _test_max1:1.0 _:2 |
|
1339 |
self new _test_max1:2.0 _:1 |
|
1340 |
self new _test_max1:1 _:2.0 |
|
1341 |
self new _test_max1:2 _:1.0 |
|
87 | 1342 |
" |
1343 |
! |
|
1344 |
||
113 | 1345 |
_test_max2:arg |
87 | 1346 |
^ 1 max:arg |
1347 |
||
1348 |
" |
|
113 | 1349 |
self new _test_max2:nil |
1350 |
self new _test_max2:0 |
|
1351 |
self new _test_max2:1 |
|
1352 |
self new _test_max2:2 |
|
1353 |
||
1354 |
self new _test_max2:0.0 |
|
1355 |
self new _test_max2:1.0 |
|
1356 |
self new _test_max2:2.0 |
|
87 | 1357 |
" |
1358 |
! |
|
1359 |
||
113 | 1360 |
_test_max3:arg |
87 | 1361 |
|var| |
1362 |
||
1363 |
var := Array new:10. |
|
1364 |
^ 1 max:arg |
|
1365 |
||
1366 |
" |
|
113 | 1367 |
self new _test_max3:nil |
1368 |
self new _test_max3:0 |
|
1369 |
self new _test_max3:1 |
|
1370 |
self new _test_max3:2 |
|
1371 |
||
1372 |
self new _test_max3:0.0 |
|
1373 |
self new _test_max3:1.0 |
|
1374 |
self new _test_max3:2.0 |
|
87 | 1375 |
" |
1376 |
! |
|
1377 |
||
113 | 1378 |
_test_max4:arg |
87 | 1379 |
|var| |
1380 |
||
1381 |
var := Array new:10. |
|
1382 |
^ arg max:1 |
|
1383 |
||
1384 |
" |
|
113 | 1385 |
self new _test_max4:nil |
1386 |
self new _test_max4:0 |
|
1387 |
self new _test_max4:1 |
|
1388 |
self new _test_max4:2 |
|
1389 |
||
1390 |
self new _test_max4:0.0 |
|
1391 |
self new _test_max4:1.0 |
|
1392 |
self new _test_max4:2.0 |
|
87 | 1393 |
" |
1394 |
! |
|
1395 |
||
113 | 1396 |
_test_min1:arg1 _:arg2 |
87 | 1397 |
^ arg1 min:arg2 |
1398 |
||
1399 |
" |
|
113 | 1400 |
self new _test_min1:nil _:nil |
1401 |
self new _test_min1:1 _:nil |
|
1402 |
self new _test_min1:nil _:1 |
|
1403 |
self new _test_min1:1 _:2 |
|
1404 |
self new _test_min1:2 _:1 |
|
1405 |
||
1406 |
self new _test_min1:1.0 _:nil |
|
1407 |
self new _test_min1:nil _:1.0 |
|
1408 |
self new _test_min1:1.0 _:2.0 |
|
1409 |
self new _test_min1:2.0 _:1.0 |
|
1410 |
||
1411 |
self new _test_min1:1.0 _:2 |
|
1412 |
self new _test_min1:2.0 _:1 |
|
1413 |
self new _test_min1:1 _:2.0 |
|
1414 |
self new _test_min1:2 _:1.0 |
|
87 | 1415 |
" |
1416 |
! |
|
1417 |
||
113 | 1418 |
_test_min2:arg |
87 | 1419 |
^ 1 min:arg |
1420 |
||
1421 |
" |
|
113 | 1422 |
self new _test_min2:nil |
1423 |
self new _test_min2:0 |
|
1424 |
self new _test_min2:1 |
|
1425 |
self new _test_min2:2 |
|
1426 |
||
1427 |
self new _test_min2:0.0 |
|
1428 |
self new _test_min2:1.0 |
|
1429 |
self new _test_min2:2.0 |
|
87 | 1430 |
" |
1431 |
! |
|
1432 |
||
113 | 1433 |
_test_min3:arg |
87 | 1434 |
|var| |
1435 |
||
1436 |
var := Array new:10. |
|
1437 |
^ 1 min:arg |
|
1438 |
||
1439 |
" |
|
113 | 1440 |
self new _test_min3:nil |
1441 |
self new _test_min3:0 |
|
1442 |
self new _test_min3:1 |
|
1443 |
self new _test_min3:2 |
|
1444 |
||
1445 |
self new _test_min3:0.0 |
|
1446 |
self new _test_min3:1.0 |
|
1447 |
self new _test_min3:2.0 |
|
87 | 1448 |
" |
1449 |
! |
|
1450 |
||
113 | 1451 |
_test_min4:arg |
87 | 1452 |
|var| |
1453 |
||
1454 |
var := Array new:10. |
|
1455 |
^ arg min:1 |
|
1456 |
||
1457 |
" |
|
113 | 1458 |
self new _test_min4:nil |
1459 |
self new _test_min4:0 |
|
1460 |
self new _test_min4:1 |
|
1461 |
self new _test_min4:2 |
|
1462 |
||
1463 |
self new _test_min4:0.0 |
|
1464 |
self new _test_min4:1.0 |
|
1465 |
self new _test_min4:2.0 |
|
87 | 1466 |
" |
1467 |
! |
|
1468 |
||
113 | 1469 |
_test_odd:arg |
87 | 1470 |
^ arg odd |
1471 |
||
1472 |
" |
|
113 | 1473 |
self new _test_odd:nil |
1474 |
self new _test_odd:123 |
|
1475 |
self new _test_odd:122 |
|
1476 |
self new _test_odd:(100 factorial) |
|
87 | 1477 |
" |
1478 |
! |
|
1479 |
||
113 | 1480 |
_test_size |
87 | 1481 |
^ value size |
1482 |
||
1483 |
" |
|
113 | 1484 |
(self new value:(Array new:2)) _test_size |
1485 |
(self new value:(OrderedCollection new:2)) _test_size |
|
1486 |
" |
|
1487 |
! ! |
|
1488 |
||
568 | 1489 |
!CompilerTest methodsFor:'tests - instvar access'! |
1490 |
||
1491 |
retInstVar |
|
1492 |
^ value |
|
1493 |
||
1494 |
" |
|
1495 |
self new retInstVar |
|
1496 |
1000000 timesRepeat:[self new retInstVar] |
|
1497 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1498 |
" |
|
1499 |
||
1500 |
" |
|
1501 |
|i| |
|
1502 |
||
1503 |
i := self new. |
|
1504 |
i instVarAt:1 put:12345. |
|
1505 |
i retInstVar |
|
1506 |
" |
|
1507 |
||
1508 |
" |
|
1509 |
|i| |
|
1510 |
i := self new. |
|
1511 |
i instVarAt:1 put:12345. |
|
1512 |
1000000 timesRepeat:[i retInstVar] |
|
1513 |
" |
|
1514 |
||
1515 |
" |
|
1516 |
|i| |
|
1517 |
i := self new. |
|
1518 |
i instVarAt:1 put:12345. |
|
1519 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
|
1520 |
" |
|
1521 |
||
1522 |
||
1523 |
! |
|
1524 |
||
1525 |
setInstVarA |
|
1526 |
value := 123 |
|
1527 |
||
1528 |
" |
|
1529 |
self new setInstVarA; instVarAt:1 |
|
1530 |
1000000 timesRepeat:[self new setInstVarA] |
|
1531 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new setInstVarA] ] |
|
1532 |
" |
|
1533 |
||
1534 |
" |
|
1535 |
|i| |
|
1536 |
||
1537 |
i := self new. |
|
1538 |
i instVarAt:1 put:12345. |
|
1539 |
i setInstVarA. |
|
1540 |
i instVarAt:1 |
|
1541 |
" |
|
1542 |
||
1543 |
||
1544 |
||
1545 |
! |
|
1546 |
||
1547 |
setInstVarB |
|
1548 |
value := 'hello' |
|
1549 |
||
1550 |
" |
|
1551 |
self new setInstVarB; instVarAt:1 |
|
1552 |
1000000 timesRepeat:[self new setInstVarB] |
|
1553 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new setInstVarB] ] |
|
1554 |
" |
|
1555 |
||
1556 |
" |
|
1557 |
|i| |
|
1558 |
||
1559 |
i := self new. |
|
1560 |
i instVarAt:1 put:12345. |
|
1561 |
i setInstVarB. |
|
1562 |
i instVarAt:1 |
|
1563 |
" |
|
1564 |
||
1565 |
||
1566 |
||
1567 |
! ! |
|
1568 |
||
1569 |
!CompilerTest methodsFor:'tests - literals'! |
|
1570 |
||
1571 |
compile:someCode |
|
1572 |
|m| |
|
1573 |
||
1574 |
m := Compiler |
|
1575 |
compile:someCode |
|
1576 |
forClass:nil |
|
1577 |
install:false. |
|
1578 |
||
1579 |
self assert:(m notNil and:[m ~~ #Error]). |
|
1580 |
^ m |
|
1581 |
! |
|
1582 |
||
1583 |
testLiterals |
|
1584 |
" |
|
1585 |
self new testLiterals |
|
1586 |
" |
|
1587 |
|m| |
|
1588 |
||
1589 |
"/ literals must be present, even if code has been optimized away |
|
1590 |
"/ (otherwise, searches do not work correctly) |
|
1591 |
||
1592 |
m := self compile:'foo:arg |v| ^ (v ~~ 0) not'. |
|
1593 |
self assert:(m literals includesIdentical:#'~~'). |
|
1594 |
self assert:(m literals includesIdentical:#'not'). |
|
1595 |
||
1596 |
m := self compile:'foo:arg |v| ^ (v == 0) not'. |
|
1597 |
self assert:(m literals includesIdentical:#'=='). |
|
1598 |
self assert:(m literals includesIdentical:#'not'). |
|
1599 |
||
1600 |
||
1601 |
m := self compile:'foo:arg ^ arg not'. |
|
1602 |
self assert:(m literals includesIdentical:#'not'). |
|
1603 |
||
1604 |
m := self compile:'foo:arg ^ arg notNil'. |
|
1605 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1606 |
m := self compile:'foo:arg ^ arg isNil'. |
|
1607 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1608 |
||
1609 |
||
1610 |
m := self compile:'foo:arg |v| v := v+1'. |
|
1611 |
self assert:(m literals includesIdentical:#'+'). |
|
1612 |
||
1613 |
m := self compile:'foo:arg |v| v := v-1'. |
|
1614 |
self assert:(m literals includesIdentical:#'-'). |
|
1615 |
||
1616 |
||
1617 |
m := self compile:'foo:arg |v| v := v not'. |
|
1618 |
self assert:(m literals includesIdentical:#'not'). |
|
1619 |
||
1620 |
||
1621 |
m := self compile:'foo:arg ^ arg ifTrue:1'. |
|
1622 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1623 |
||
1624 |
m := self compile:'foo:arg ^ arg ifFalse:1'. |
|
1625 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1626 |
||
1627 |
m := self compile:'foo:arg ^ arg ifTrue:1 ifFalse:2'. |
|
1628 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1629 |
||
1630 |
m := self compile:'foo:arg ^ arg ifFalse:1 ifTrue:2'. |
|
1631 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1632 |
||
1633 |
||
1634 |
m := self compile:'foo:arg ^ arg isNil ifTrue:1'. |
|
1635 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1636 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1637 |
||
1638 |
m := self compile:'foo:arg ^ arg isNil ifFalse:1'. |
|
1639 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1640 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1641 |
||
1642 |
m := self compile:'foo:arg ^ arg isNil ifTrue:1 ifFalse:2'. |
|
1643 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1644 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1645 |
||
1646 |
m := self compile:'foo:arg ^ arg isNil ifFalse:1 ifTrue:2'. |
|
1647 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1648 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1649 |
||
1650 |
||
1651 |
m := self compile:'foo:arg ^ arg notNil ifTrue:1'. |
|
1652 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1653 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1654 |
||
1655 |
m := self compile:'foo:arg ^ arg notNil ifFalse:1'. |
|
1656 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1657 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1658 |
||
1659 |
m := self compile:'foo:arg ^ arg notNil ifTrue:1 ifFalse:2'. |
|
1660 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1661 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1662 |
||
1663 |
m := self compile:'foo:arg ^ arg notNil ifFalse:1 ifTrue:2'. |
|
1664 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1665 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1666 |
||
1667 |
||
1668 |
m := self compile:'foo:arg ^ arg not ifTrue:1'. |
|
1669 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1670 |
self assert:(m literals includesIdentical:#'not'). |
|
1671 |
||
1672 |
m := self compile:'foo:arg ^ arg not ifFalse:1'. |
|
1673 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1674 |
self assert:(m literals includesIdentical:#'not'). |
|
1675 |
||
1676 |
m := self compile:'foo:arg ^ arg not ifTrue:1 ifFalse:2'. |
|
1677 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1678 |
self assert:(m literals includesIdentical:#'not'). |
|
1679 |
||
1680 |
m := self compile:'foo:arg ^ arg not ifFalse:1 ifTrue:2'. |
|
1681 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1682 |
self assert:(m literals includesIdentical:#'not'). |
|
1683 |
||
1684 |
||
1685 |
m := self compile:'foo:arg ^ arg and:[true]'. |
|
1686 |
self assert:(m literals includesIdentical:#'and:'). |
|
1687 |
||
1688 |
m := self compile:'foo:arg ^ arg not and:[true]'. |
|
1689 |
self assert:(m literals includesIdentical:#'and:'). |
|
1690 |
self assert:(m literals includesIdentical:#'not'). |
|
1691 |
||
1692 |
m := self compile:'foo:arg ^ arg or:[true]'. |
|
1693 |
self assert:(m literals includesIdentical:#'or:'). |
|
1694 |
||
1695 |
m := self compile:'foo:arg ^ arg not or:[true]'. |
|
1696 |
self assert:(m literals includesIdentical:#'or:'). |
|
1697 |
self assert:(m literals includesIdentical:#'not'). |
|
1698 |
||
1699 |
m := self compile:'foo:arg ^ (arg or:[true]) ifTrue:[1234]'. |
|
1700 |
self assert:(m literals includesIdentical:#'or:'). |
|
1701 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1702 |
||
1703 |
m := self compile:'foo:arg ^ (arg or:[true]) ifFalse:[1234]'. |
|
1704 |
self assert:(m literals includesIdentical:#'or:'). |
|
1705 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1706 |
||
1707 |
m := self compile:'foo:arg ^ (arg or:[true]) ifTrue:1 ifFalse:2'. |
|
1708 |
self assert:(m literals includesIdentical:#'or:'). |
|
1709 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1710 |
||
1711 |
m := self compile:'foo:arg ^ (arg or:[true]) ifFalse:1 ifTrue:2'. |
|
1712 |
self assert:(m literals includesIdentical:#'or:'). |
|
1713 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1714 |
||
1715 |
||
1716 |
m := self compile:'foo:arg ^ [ ] loop'. |
|
1717 |
self assert:(m literals includesIdentical:#'loop'). |
|
1718 |
||
1719 |
m := self compile:'foo:arg ^ [ ] repeat'. |
|
1720 |
self assert:(m literals includesIdentical:#'repeat'). |
|
1721 |
||
1722 |
m := self compile:'foo:arg ^ arg ? 123'. |
|
1723 |
self assert:(m literals includesIdentical:#'?'). |
|
1724 |
||
1725 |
" |
|
1726 |
self new testLiterals |
|
1727 |
" |
|
1728 |
! ! |
|
1729 |
||
188 | 1730 |
!CompilerTest methodsFor:'tests - method calls'! |
1731 |
||
189 | 1732 |
addDumpingMethodForSelfIsLostBug |
1733 |
|code mthd| |
|
1734 |
||
1735 |
code := |
|
1736 |
'_x |
|
190 | 1737 |
"/ ObjectMemory dumpSender. |
189 | 1738 |
"/ request nextPutAll: ''a''. |
1739 |
ObjectMemory garbageCollect. |
|
1740 |
ObjectMemory dumpSender. |
|
1741 |
"/ request nextPutAll: ''b''. |
|
1742 |
'. |
|
1743 |
||
1744 |
Class withoutUpdatingChangesDo:[ |
|
1745 |
mthd := (Smalltalk at:#Compiler) |
|
1746 |
compile:code |
|
1747 |
in:DummyClass |
|
1748 |
notifying:nil |
|
1749 |
ifFail:[self error]. |
|
1750 |
]. |
|
1751 |
^ mthd |
|
1752 |
! |
|
1753 |
||
1754 |
addHaltingMethodForSelfIsLostBug |
|
1755 |
|code mthd| |
|
1756 |
||
1757 |
code := |
|
1758 |
'_x |
|
1759 |
request nextPutAll: ''a''. |
|
1760 |
self halt. |
|
1761 |
ObjectMemory garbageCollect. |
|
1762 |
self halt. |
|
1763 |
request nextPutAll: ''b''. |
|
1764 |
'. |
|
1765 |
||
1766 |
Class withoutUpdatingChangesDo:[ |
|
1767 |
mthd := (Smalltalk at:#Compiler) |
|
1768 |
compile:code |
|
1769 |
in:DummyClass |
|
1770 |
notifying:nil |
|
1771 |
ifFail:[self error]. |
|
1772 |
]. |
|
1773 |
^ mthd |
|
1774 |
! |
|
1775 |
||
188 | 1776 |
addMethodForSelfIsLostBug |
1777 |
|code mthd| |
|
1778 |
||
1779 |
code := |
|
1780 |
'_x |
|
1781 |
request nextPutAll: ''a''. |
|
1782 |
ObjectMemory garbageCollect. |
|
1783 |
request nextPutAll: ''b''. |
|
1784 |
'. |
|
1785 |
||
1786 |
Class withoutUpdatingChangesDo:[ |
|
1787 |
mthd := (Smalltalk at:#Compiler) |
|
1788 |
compile:code |
|
1789 |
in:DummyClass |
|
1790 |
notifying:nil |
|
1791 |
ifFail:[self error]. |
|
1792 |
]. |
|
1793 |
^ mthd |
|
1794 |
! |
|
1795 |
||
1796 |
removeMethodForSelfIsLostBug |
|
1797 |
Class withoutUpdatingChangesDo:[ |
|
1798 |
DummyClass removeSelector:#'_x'. |
|
1799 |
]. |
|
1800 |
! |
|
1801 |
||
1802 |
test_selfIsLost1 |
|
1803 |
|mthd rcvr retVal str| |
|
1804 |
||
1805 |
str := '' writeStream. |
|
1806 |
||
1807 |
mthd := self addMethodForSelfIsLostBug. |
|
1808 |
self removeMethodForSelfIsLostBug. |
|
1809 |
rcvr := DummyClass new. |
|
1810 |
rcvr request:str. |
|
1811 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
191 | 1812 |
self assert:(retVal == rcvr). |
1813 |
self assert:(str contents = 'ab'). |
|
188 | 1814 |
|
1815 |
" |
|
1816 |
self new test_selfIsLost1 |
|
1817 |
" |
|
1818 |
! |
|
1819 |
||
1820 |
test_selfIsLost2 |
|
1821 |
|mthd rcvr retVal str| |
|
1822 |
||
1823 |
str := '' writeStream. |
|
1824 |
||
1825 |
mthd := self addMethodForSelfIsLostBug. |
|
1826 |
rcvr := DummyClass new. |
|
1827 |
rcvr request:str. |
|
1828 |
||
1829 |
retVal := rcvr perform:#'_x'. |
|
1830 |
||
1831 |
self removeMethodForSelfIsLostBug. |
|
1832 |
||
191 | 1833 |
self assert:(retVal == rcvr). |
1834 |
self assert:(str contents = 'ab'). |
|
1835 |
||
188 | 1836 |
" |
1837 |
self new test_selfIsLost2 |
|
1838 |
" |
|
1839 |
! |
|
1840 |
||
1841 |
test_selfIsLost3 |
|
1842 |
|mthd rcvr retVal| |
|
1843 |
||
1844 |
mthd := DummyClass compiledMethodAt:#'_y0'. |
|
1845 |
||
1846 |
rcvr := DummyClass new. |
|
1847 |
||
1848 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1849 |
self assert:(retVal == rcvr). |
|
1850 |
||
1851 |
" |
|
1852 |
self new test_selfIsLost3 |
|
1853 |
" |
|
1854 |
! |
|
1855 |
||
1856 |
test_selfIsLost4 |
|
1857 |
|mthd rcvr retVal| |
|
1858 |
||
1859 |
mthd := DummyClass compiledMethodAt:#'_y1:'. |
|
1860 |
||
1861 |
rcvr := DummyClass new. |
|
1862 |
||
1863 |
retVal := mthd valueWithReceiver:rcvr arguments:(Array with:rcvr). |
|
191 | 1864 |
self assert:(retVal == rcvr). |
188 | 1865 |
|
1866 |
" |
|
1867 |
self new test_selfIsLost4 |
|
1868 |
" |
|
189 | 1869 |
! |
1870 |
||
1871 |
xtest_selfIsLost5 |
|
1872 |
|mthd rcvr retVal str| |
|
1873 |
||
1874 |
str := '' writeStream. |
|
1875 |
||
1876 |
mthd := self addHaltingMethodForSelfIsLostBug. |
|
1877 |
self removeMethodForSelfIsLostBug. |
|
1878 |
rcvr := DummyClass new. |
|
1879 |
rcvr request:str. |
|
1880 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1881 |
||
1882 |
" |
|
1883 |
self new xtest_selfIsLost5 |
|
1884 |
" |
|
1885 |
! |
|
1886 |
||
1887 |
xtest_selfIsLost6 |
|
1888 |
|mthd rcvr retVal str| |
|
1889 |
||
1890 |
str := '' writeStream. |
|
1891 |
||
1892 |
mthd := self addDumpingMethodForSelfIsLostBug. |
|
1893 |
self removeMethodForSelfIsLostBug. |
|
1894 |
rcvr := DummyClass new. |
|
1895 |
rcvr request:str. |
|
1896 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1897 |
||
1898 |
" |
|
1899 |
self new xtest_selfIsLost6 |
|
1900 |
" |
|
188 | 1901 |
! ! |
1902 |
||
113 | 1903 |
!CompilerTest methodsFor:'tests - parsing'! |
1904 |
||
1905 |
testParseBadLiteral |
|
1906 |
self assert:( (self class compile:'foo ^ #( a b ( c d (' ) == #Error ) . |
|
1907 |
self assert:( (self class compile:'foo ^ #( a b ( c d ()' ) == #Error ). |
|
1908 |
self assert:( (self class compile:'foo ^ #( a b ( c d ())' ) == #Error ). |
|
1909 |
self assert:( (self class compile:'foo ^ #( a b ( c d ()))' ) ~~ #Error ). |
|
1910 |
self class removeSelector:#foo. |
|
1911 |
||
1912 |
" |
|
1913 |
self new testParseBadLiteral |
|
87 | 1914 |
" |
318 | 1915 |
! |
1916 |
||
1917 |
testParseExtendedSyntax |
|
1918 |
|compiler val| |
|
1919 |
||
1920 |
compiler := Parser new. |
|
1921 |
val := compiler evaluate:' ''12\t34'' '. |
|
1922 |
self assert:( val = '12\t34' ) . |
|
1923 |
val := compiler evaluate:' ''12\u161634'' '. |
|
1924 |
self assert:( val = '12\u161634' ) . |
|
1925 |
||
1926 |
compiler parserFlags allowExtendedSTXSyntax:true. |
|
1927 |
val := compiler evaluate:' ''12\t34'' '. |
|
1928 |
self assert:( val = ('12' , Character tab , '34' )) . |
|
1929 |
val := compiler evaluate:' ''12\u161634'' '. |
|
1930 |
self assert:( val = ('12' , (Character value:16r1616) , '34' )) . |
|
1931 |
||
1932 |
" |
|
1933 |
self new testParseExtendedSyntax |
|
1934 |
" |
|
87 | 1935 |
! ! |
1936 |
||
328 | 1937 |
!CompilerTest methodsFor:'tests - return'! |
1938 |
||
1939 |
test_bad_return2 |
|
329 | 1940 |
|w a| |
1941 |
||
1942 |
w := ParserFlags warnAboutPossibleSTCCompilationProblems. |
|
1943 |
a := ParserFlags allowPossibleSTCCompilationProblems. |
|
1944 |
||
1945 |
[ |
|
1946 |
ParserFlags warnAboutPossibleSTCCompilationProblems:true. |
|
1947 |
ParserFlags allowPossibleSTCCompilationProblems:false. |
|
1948 |
||
1949 |
self |
|
1950 |
should: |
|
1951 |
[ |
|
1952 |
Compiler |
|
1953 |
compile:' |
|
328 | 1954 |
foo:arg |
1955 |
^ arg |
|
1956 |
ifTrue:[^ 1] |
|
1957 |
ifFalse:[2] |
|
1958 |
' |
|
329 | 1959 |
forClass:self class. |
1960 |
] |
|
1961 |
raise:Parser::ParseError. |
|
1962 |
] ensure:[ |
|
1963 |
ParserFlags warnAboutPossibleSTCCompilationProblems:w. |
|
1964 |
ParserFlags allowPossibleSTCCompilationProblems:a. |
|
1965 |
]. |
|
328 | 1966 |
|
1967 |
"Created: / 16-11-2006 / 14:08:48 / cg" |
|
1968 |
! |
|
1969 |
||
1970 |
test_bad_return3 |
|
329 | 1971 |
|w a setOfSignals| |
1972 |
||
1973 |
w := ParserFlags warnAboutPossibleSTCCompilationProblems. |
|
1974 |
a := ParserFlags allowPossibleSTCCompilationProblems. |
|
1975 |
||
1976 |
[ |
|
1977 |
ParserFlags warnAboutPossibleSTCCompilationProblems:false. |
|
1978 |
ParserFlags allowPossibleSTCCompilationProblems:true. |
|
1979 |
||
1980 |
setOfSignals := SignalSet with:(Parser::ParseError) with:(Parser::ParseWarning). |
|
1981 |
self |
|
1982 |
shouldnt: |
|
1983 |
[ |
|
1984 |
Compiler |
|
1985 |
compile:' |
|
328 | 1986 |
foo:arg |
1987 |
^ arg |
|
1988 |
ifTrue:[^ 1] |
|
1989 |
ifFalse:[2] |
|
1990 |
' |
|
329 | 1991 |
forClass:self class. |
1992 |
] |
|
1993 |
raise:setOfSignals. |
|
1994 |
] ensure:[ |
|
1995 |
ParserFlags warnAboutPossibleSTCCompilationProblems:w. |
|
1996 |
ParserFlags allowPossibleSTCCompilationProblems:a. |
|
1997 |
] |
|
328 | 1998 |
|
1999 |
"Created: / 16-11-2006 / 14:33:29 / cg" |
|
2000 |
! |
|
2001 |
||
2002 |
test_good_return1 |
|
2003 |
|setOfPossibleExceptions| |
|
2004 |
||
2005 |
setOfPossibleExceptions := SignalSet with:(Parser::ParseWarning) with:(Parser::ParseError). |
|
2006 |
self |
|
2007 |
shouldnt: |
|
2008 |
[ |
|
2009 |
Compiler |
|
2010 |
compile:' |
|
2011 |
foo:arg |
|
2012 |
arg |
|
2013 |
ifTrue:[^ 1] |
|
2014 |
ifFalse:[^ 2] |
|
2015 |
' |
|
2016 |
forClass:self class. |
|
2017 |
] |
|
2018 |
raise:setOfPossibleExceptions. |
|
2019 |
||
2020 |
"Created: / 16-11-2006 / 14:16:53 / cg" |
|
2021 |
! |
|
2022 |
||
2023 |
test_good_return2 |
|
2024 |
|setOfPossibleExceptions| |
|
2025 |
||
2026 |
setOfPossibleExceptions := SignalSet with:(Parser::ParseWarning) with:(Parser::ParseError). |
|
2027 |
self |
|
2028 |
shouldnt: |
|
2029 |
[ |
|
2030 |
Compiler |
|
2031 |
compile:' |
|
2032 |
foo:arg |
|
2033 |
^ arg |
|
2034 |
ifTrue:[1] |
|
2035 |
ifFalse:[2] |
|
2036 |
' |
|
2037 |
forClass:self class. |
|
2038 |
] |
|
2039 |
raise:setOfPossibleExceptions. |
|
2040 |
||
2041 |
"Created: / 16-11-2006 / 14:41:45 / cg" |
|
2042 |
! ! |
|
2043 |
||
84 | 2044 |
!CompilerTest methodsFor:'tests - sends'! |
2045 |
||
2046 |
m1 |
|
2047 |
^ 123 |
|
2048 |
! |
|
2049 |
||
85 | 2050 |
m10 |
2051 |
^ self m9 |
|
2052 |
||
2053 |
" |
|
2054 |
self new m10 |
|
2055 |
" |
|
2056 |
! |
|
2057 |
||
2058 |
m11 |
|
2059 |
^ self m10 |
|
2060 |
||
2061 |
" |
|
2062 |
self new m11 |
|
2063 |
" |
|
2064 |
! |
|
2065 |
||
2066 |
m12 |
|
2067 |
^ self m11 |
|
2068 |
||
2069 |
" |
|
2070 |
self new m12 |
|
2071 |
" |
|
2072 |
! |
|
2073 |
||
2074 |
m13 |
|
2075 |
^ self m12 |
|
2076 |
||
2077 |
" |
|
2078 |
self new m13 |
|
2079 |
" |
|
2080 |
! |
|
2081 |
||
2082 |
m14 |
|
2083 |
^ self m13 |
|
2084 |
||
2085 |
" |
|
2086 |
self new m14 |
|
2087 |
" |
|
2088 |
! |
|
2089 |
||
2090 |
m15 |
|
2091 |
^ self m14 |
|
2092 |
||
2093 |
" |
|
2094 |
self new m15 |
|
2095 |
" |
|
2096 |
! |
|
2097 |
||
2098 |
m16 |
|
2099 |
^ self m15 |
|
2100 |
||
2101 |
" |
|
2102 |
self new m16 |
|
2103 |
" |
|
2104 |
! |
|
2105 |
||
84 | 2106 |
m2 |
2107 |
^ self m1 |
|
2108 |
! |
|
2109 |
||
2110 |
m3 |
|
2111 |
^ self m2 |
|
2112 |
! |
|
2113 |
||
2114 |
m4 |
|
2115 |
^ self m3 |
|
2116 |
! |
|
2117 |
||
2118 |
m5 |
|
2119 |
^ self m4 |
|
2120 |
! |
|
2121 |
||
2122 |
m6 |
|
2123 |
^ self m5 |
|
2124 |
! |
|
2125 |
||
2126 |
m7 |
|
2127 |
^ self m6 |
|
2128 |
||
2129 |
" |
|
2130 |
self new m7 |
|
2131 |
" |
|
85 | 2132 |
! |
2133 |
||
2134 |
m8 |
|
2135 |
^ self m7 |
|
2136 |
||
2137 |
" |
|
2138 |
self new m8 |
|
2139 |
" |
|
2140 |
! |
|
2141 |
||
2142 |
m9 |
|
2143 |
^ self m8 |
|
2144 |
||
2145 |
" |
|
2146 |
self new m9 |
|
2147 |
" |
|
84 | 2148 |
! ! |
2149 |
||
568 | 2150 |
!CompilerTest methodsFor:'tests - specials'! |
2151 |
||
2152 |
testEnsure |
|
2153 |
self assert:(self callEnsureWith2Returns = true). |
|
2154 |
||
2155 |
"Created: / 24-08-2010 / 12:51:27 / cg" |
|
213
9764b38bebf5
test for all literals to be present in the method
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
2156 |
! ! |
9764b38bebf5
test for all literals to be present in the method
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
2157 |
|
188 | 2158 |
!CompilerTest::DummyClass methodsFor:'accessing'! |
2159 |
||
2160 |
_y0 |
|
2161 |
ObjectMemory garbageCollect. |
|
2162 |
^ self. |
|
2163 |
! |
|
2164 |
||
2165 |
_y1:arg1 |
|
2166 |
ObjectMemory garbageCollect. |
|
2167 |
^ arg1. |
|
2168 |
! |
|
2169 |
||
2170 |
request:something |
|
2171 |
"set the value of the instance variable 'request' (automatically generated)" |
|
2172 |
||
2173 |
request := something. |
|
2174 |
! ! |
|
2175 |
||
47 | 2176 |
!CompilerTest class methodsFor:'documentation'! |
2177 |
||
2178 |
version |
|
2179 |
^ '$Header$' |
|
568 | 2180 |
! |
2181 |
||
2182 |
version_CVS |
|
2183 |
^ '$Header$' |
|
47 | 2184 |
! ! |