/
FLHookedSubstitutionTest.class.st
172 lines (122 loc) · 5.13 KB
/
FLHookedSubstitutionTest.class.st
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
"
SUnit tests for hooked serialization using fuel
"
Class {
#name : #FLHookedSubstitutionTest,
#superclass : #FLSerializationTest,
#category : #'Fuel-Tests-Core-Base'
}
{ #category : #tests }
FLHookedSubstitutionTest >> testAvoidRecursion [
| result original |
original := FLClassWithRecursiveSubstitution new index: 1.
result := self resultOfSerializeAndMaterialize: original.
self assert: result index equals: 2
]
{ #category : #tests }
FLHookedSubstitutionTest >> testClassWithCachedValueByNil [
| aClassWithCachedValue result original |
aClassWithCachedValue := (self newSubclassOf: Object instanceVariableNames: 'cache' classVariableNames: '')
duringTestCompileSilently: 'cache ^cache';
duringTestCompileSilently: 'cache: x cache := x';
duringTestCompileSilently: '
fuelAccept: aVisitor
^cache
ifNil: [ super fuelAccept: aVisitor ]
ifNotNil: [ aVisitor visitSubstitution: self by: (self copy cache: nil)]';
yourself.
original := aClassWithCachedValue new cache: 5; yourself.
result := self resultOfSerializeAndMaterialize: original.
self assert: result cache isNil.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testObjectByProxyThatBecomesItsContent [
"Tests a substitution of an object by a proxy that becomes another object on materialization."
| aProxyClass result |
aProxyClass := (self newSubclassOf: Object instanceVariableNames: 'someState' classVariableNames: '')
duringTestCompileSilently: 'initialize someState := 5@1';
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: (FLProxyThatBecomesItsContent newWith: someState)';
yourself.
result := self resultOfSerializeAndMaterialize: aProxyClass new.
self assert: 5@1 = result.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testProxyByTarget [
| aProxyClass result original |
aProxyClass := (self newSubclassOf: Object instanceVariableNames: 'target' classVariableNames: '')
duringTestCompileSilently: 'target: x target := x';
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: target';
yourself.
original := aProxyClass new target: 5; yourself.
result := self resultOfSerializeAndMaterialize: original.
self assert: 5 = result.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testProxyByTargetAnalisysIsPropagated [
| aProxyClass result pair |
self flag: #pharoTodo. "I don't understand what are we testing here."
aProxyClass := (self newSubclassOf: Object instanceVariableNames: 'target' classVariableNames: '')
duringTestCompileSilently: 'target: x target := x';
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: target';
yourself.
pair := FLPair new.
pair left: 6.
pair right: 'foo'.
aProxyClass new target: pair; yourself.
result := self resultOfSerializeAndMaterialize: pair.
self assert: result left = 6.
self assert: result right = 'foo'.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testProxyByTargetInsideObjectAndAnalisysIsPropagated [
| aProxyClass result original pair pairRoot |
aProxyClass := (self newSubclassOf: Object instanceVariableNames: 'target' classVariableNames: '')
duringTestCompileSilently: 'target: x target := x';
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: target';
yourself.
pair := FLPair new.
pair left: 6.
pair right: 'foo'.
original := aProxyClass new target: pair; yourself.
pairRoot := FLPair new left: original; yourself.
result := self resultOfSerializeAndMaterialize: pairRoot.
self assert: result left left = 6.
self assert: result left right = 'foo'.
self assert: result right isNil.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testProxyInsideObjectByTarget [
| aProxyClass result original pair |
aProxyClass := (self newSubclassOf: Object instanceVariableNames: 'target' classVariableNames: '')
duringTestCompileSilently: 'target: x target := x';
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: target';
yourself.
original := aProxyClass new target: 5; yourself.
pair := FLPair new.
pair left: original.
pair right: 'foo'.
result := self resultOfSerializeAndMaterialize: pair.
self assert: result left = 5.
self assert: result right = 'foo'.
]
{ #category : #tests }
FLHookedSubstitutionTest >> testSubstituteByItself [
| aRecursiveClass result |
aRecursiveClass := (self newSubclassOf: Object instanceVariableNames: '' classVariableNames: '')
duringTestCompileSilently: 'fuelAccept: aMapper
^aMapper
visitSubstitution: self by: self
onRecursionDo: [super fuelAccept: aMapper]';
yourself.
result := self resultOfSerializeAndMaterialize: aRecursiveClass new.
"self flag: #todo." "Should test that it doesn't enter in loop."
]
{ #category : #tests }
FLHookedSubstitutionTest >> testTransientByNil [
| result aClassOfTransientObjects |
aClassOfTransientObjects := self newClass
duringTestCompileSilently: 'fuelAccept: aVisitor ^aVisitor visitSubstitution: self by: nil';
yourself.
result := self resultOfSerializeAndMaterialize: aClassOfTransientObjects new.
self assert: result isNil.
]