|
1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 TestCase subclass:#PPCCopyVisitorTest |
|
6 instanceVariableNames:'node result visitor' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Tests-Visitors' |
|
10 ! |
|
11 |
|
12 !PPCCopyVisitorTest methodsFor:'as yet unclassified'! |
|
13 |
|
14 assert: object equal: anotherObject |
|
15 self assert: object = anotherObject |
|
16 ! |
|
17 |
|
18 assert: object identical: anotherObject |
|
19 self assert: (object == anotherObject) |
|
20 ! |
|
21 |
|
22 assert: object notIdentical: anotherObject |
|
23 self assert: (object == anotherObject) not |
|
24 ! |
|
25 |
|
26 setUp |
|
27 visitor := PPCCopyVisitor new |
|
28 ! |
|
29 |
|
30 testCopy1 |
|
31 node := PPCNilNode new. |
|
32 result := visitor visit: node. |
|
33 |
|
34 self assert: node equal: result. |
|
35 self assert: node notIdentical: result |
|
36 ! |
|
37 |
|
38 testCopy2 |
|
39 | nilNode | |
|
40 nilNode := PPCNilNode new. |
|
41 node := PPCForwardNode new |
|
42 child: nilNode; |
|
43 yourself. |
|
44 |
|
45 result := visitor visit: node. |
|
46 |
|
47 self assert: result notIdentical: node. |
|
48 self assert: result equal: node. |
|
49 self assert: result child notIdentical: node child. |
|
50 self assert: result child equal: node child. |
|
51 |
|
52 self assert: node child identical: nilNode. |
|
53 ! |
|
54 |
|
55 testCopyCycle |
|
56 | forwardNode | |
|
57 forwardNode := PPCForwardNode new |
|
58 child: nil; |
|
59 yourself. |
|
60 node := PPCForwardNode new |
|
61 child: forwardNode; |
|
62 yourself. |
|
63 forwardNode child: node. |
|
64 |
|
65 result := visitor visit: node. |
|
66 |
|
67 self assert: (result == node) not. |
|
68 self assert: (result = node). |
|
69 self assert: (result child == node child) not. |
|
70 self assert: (result child = node child). |
|
71 |
|
72 self assert: node child == forwardNode. |
|
73 self assert: forwardNode child == node. |
|
74 ! ! |
|
75 |