-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
RBTransformationTest.class.st
182 lines (150 loc) · 4.57 KB
/
RBTransformationTest.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
173
174
175
176
177
178
179
180
181
182
Class {
#name : #RBTransformationTest,
#superclass : #TestCase,
#instVars : [
'manager',
'model'
],
#category : #'Refactoring2-Transformations-Tests'
}
{ #category : #mocking }
RBTransformationTest >> abstractVariableTestData [
| newModel classEnvironment classes |
classes := #(#Bar #Foo)
inject: OrderedCollection new
into: [ :sum :each |
aTestEnvironment at: each ifPresent: [ :class |
sum add: class; add: class class ].
sum ].
classEnvironment := RBClassEnvironment classes: classes.
newModel := RBNamespace2 onEnvironment: classEnvironment not.
newModel name: 'Test'.
#('Object subclass: #Foo
instanceVariableNames: ''instVarName1 instVarName2''
classVariableNames: ''ClassVarName1 ClassVarName2 ''
poolDictionaries: ''''
category: ''Testing'' '
'Foo subclass: #Bar
instanceVariableNames: ''''
classVariableNames: ''''
poolDictionaries: ''''
category: ''Testing'' '
) do: [ :each | newModel defineClass: each ].
#(#(#Bar #(
#('instVarName1
^1242321' #tests)
#('foo
instVarName1 := instVarName1 + instVarName2 + ClassVarName1' #tests)))
#(#Foo #(
#('foo
^instVarName2 := 3' #tests)
#('bar
"Add one to instVarName1"
instVarName1 := instVarName1 + 1' #tests)
#('classVarName1
^ClassVarName1' #tests)
#('instVarName1: anObject
^anObject' #tests)
#('asdf
^self classVarName1: (ClassVarName1 := ClassVarName1 + 1)' #tests)
#('instVarName2
^instVarName2' #tests)
#('instVarName2: anObject
instVarName2 := anObject' #tests)
#('classVarName1: anObject
^ClassVarName1 := anObject' #tests)))
#('Bar class' #(
#('classVarName2: anObject
ClassVarName2 := anObject' #tests)
#('classVarName2
^ClassVarName2' #tests)))
#('Foo class' #(
#('foo
^ClassVarName1 := ClassVarName1 * ClassVarName1 * ClassVarName1' #tests))))
do: [:each |
| class |
class := newModel classNamed: each first.
each last do: [ :methodPair |
class
compile: methodPair first
classified: methodPair last]].
^ newModel
]
{ #category : #mocking }
RBTransformationTest >> changeMock [
^ aTestEnvironment at: #RBRefactoringChangeMock
]
{ #category : #mocking }
RBTransformationTest >> createMockClass [
self class compiler evaluate: 'Object subclass: #RBRefactoringChangeMock
instanceVariableNames: ''instVar''
classVariableNames: ''ClassVar''
poolDictionaries: ''''
category: ''Refactoring-Tests-Changes'''.
self class compiler evaluate: 'RBRefactoringChangeMock class
instanceVariableNames: ''classInstVar'''.
self changeMock compile: 'one ^ 1' classified: 'accessing'.
]
{ #category : #mocking }
RBTransformationTest >> objectClassVariable [
^ Object classPool keys detect: [:each | true]
]
{ #category : #parsing }
RBTransformationTest >> parseMethod: aString [
^ self parserClass parseMethod: aString
]
{ #category : #parsing }
RBTransformationTest >> parserClass [
^ RBParser
]
{ #category : #running }
RBTransformationTest >> perform: aChange do: aBlock [
"Perform a change in the system silently, evaluate aBlock and then undo the change again."
| undo |
^ SystemAnnouncer uniqueInstance suspendAllWhile: [
undo := aChange execute.
aBlock ensure: [ undo execute ] ]
]
{ #category : #running }
RBTransformationTest >> proceedThroughWarning: aBlock [
aBlock
on: RBRefactoringError
do: [ :ex | ex resume ]
]
{ #category : #mocking }
RBTransformationTest >> removeMockClass [
aTestEnvironment removeClassNamed: #RBRefactoringChangeMock.
]
{ #category : #running }
RBTransformationTest >> setUp [
super setUp.
self createMockClass.
model := RBNamespace2 new
]
{ #category : #running }
RBTransformationTest >> shouldFail: aRefactoring [
self proceedThroughWarning: [
self should: [ aRefactoring transform ] raise: RBRefactoringError ]
]
{ #category : #running }
RBTransformationTest >> tearDown [
self removeMockClass.
super tearDown
]
{ #category : #testing }
RBTransformationTest >> testAPI [
"all classes must implement #storeOn: and #transform"
| incompleteTransformations |
incompleteTransformations := RBTransformation allSubclasses
select: [ :each |
| selectors |
selectors := each methods collect: #selector.
each subclasses isEmpty and: [ (selectors includes: #privateTransform) not and: [ (selectors includes: #storeOn:) not ] ] ].
self assertEmpty: incompleteTransformations.
incompleteTransformations := RBCompositeTransformation allSubclasses
select: [ :each |
| selectors |
selectors := each methods collect: #selector.
each subclasses isEmpty and: [ (selectors includes: #buildTransformations) not ] ].
self assertEmpty: incompleteTransformations
]