/
RBRemoveDirectAccessToVariableTransformationTest.class.st
182 lines (155 loc) · 5.69 KB
/
RBRemoveDirectAccessToVariableTransformationTest.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 : #RBRemoveDirectAccessToVariableTransformationTest,
#superclass : #RBTransformationTest,
#category : #'Refactoring2-Transformations-Tests'
}
{ #category : #running }
RBRemoveDirectAccessToVariableTransformationTest >> setUp [
super setUp.
model := self abstractVariableTestData.
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testClassVariable [
| refactoring class |
refactoring := (RBRemoveDirectAccessToVariableTransformation
classVariable: 'UndoSize'
class: #RBRefactoryChangeManager)
asRefactoring transform.
self assert: refactoring model changes changes size equals: 2.
class := (refactoring model classNamed: #RBRefactoryChangeManager) theMetaClass.
self assert: (class parseTreeFor: #initialize)
equals: (self parseMethod: 'initialize self nuke. self undoSize: 20').
self assert: (class theNonMetaClass parseTreeFor: #addUndo:)
equals: (self parseMethod: 'addUndo: aRefactoringChange
undo push: aRefactoringChange.
undo size > self class undoSize
ifTrue: [ undo removeFirst ].
redo := OrderedCollection new')
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testDoesNotDefineVariable [
self
shouldFail: (RBRemoveDirectAccessToVariableTransformation
model: model
instanceVariable: 'instVarName1'
class: #Bar)
asRefactoring;
shouldFail: (RBRemoveDirectAccessToVariableTransformation
classVariable: 'Foo1'
class: #RBFooLintRuleTestData)
asRefactoring
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testDoesNotUnderstandAccessors [
self
shouldFail: (RBRemoveDirectAccessToVariableTransformation
model: model
instanceVariable: 'instVarName1'
class: #Foo)
asRefactoring;
shouldFail: (RBRemoveDirectAccessToVariableTransformation
classVariable: 'RecursiveSelfRule'
class: #RBTransformationRuleTestData)
asRefactoring
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testInheritedName [
self
shouldFail: (RBRemoveDirectAccessToVariableTransformation
instanceVariable: 'name'
class: #RBBasicLintRuleTestData)
asRefactoring;
shouldFail: (RBRemoveDirectAccessToVariableTransformation
classVariable: #DependentsFields
class: #RBBasicLintRuleTestData)
asRefactoring
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testInstanceVariable [
| class |
(RBRemoveDirectAccessToVariableTransformation
model: model
instanceVariable: 'instVarName2'
class: #Foo)
asRefactoring transform.
class := model classNamed: #Foo.
self assert: (class parseTreeFor: #foo)
equals: (self parseMethod: 'foo ^ self instVarName2: 3')
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testMetaclassFailure [
self shouldFail: (RBRemoveDirectAccessToVariableTransformation
classVariable: #RecursiveSelfRule
class: RBTransformationRuleTestData class)
asRefactoring
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testNonExistantName [
self
shouldFail: (RBRemoveDirectAccessToVariableTransformation
instanceVariable: 'foo'
class: #RBBasicLintRuleTestData)
asRefactoring;
shouldFail: (RBRemoveDirectAccessToVariableTransformation
classVariable: #Foo
class: #RBBasicLintRuleTestData)
asRefactoring
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testRefactoring [
| refactoring class |
refactoring := (RBRemoveDirectAccessToVariableTransformation
instanceVariable: 'environment'
class: #RBNamespace)
asRefactoring transform.
self assert: refactoring model changes changes size equals: 6.
class := refactoring model classNamed: #RBNamespace.
self assert: (class parseTreeFor: #includesGlobal:)
equals: (self parseMethod: 'includesGlobal: aSymbol
(self hasRemoved: aSymbol) ifTrue: [^false].
(self includesClassNamed: aSymbol) ifTrue: [^true].
self environment at: aSymbol ifAbsent: [^false].
^ true').
self assert: (class parseTreeFor: #initialize)
equals: (self parseMethod: 'initialize
super initialize.
changes := RBRefactoryChangeManager changeFactory compositeRefactoryChange.
self environment: RBBrowserEnvironment new.
newClasses := IdentityDictionary new.
changedClasses := IdentityDictionary new.
removedClasses := Set new.
implementorsCache := IdentityDictionary new.
sendersCache := IdentityDictionary new')
]
{ #category : #testing }
RBRemoveDirectAccessToVariableTransformationTest >> testTransform [
| transformation class |
transformation := (RBRemoveDirectAccessToVariableTransformation
instanceVariable: 'class'
class: #RBTransformationRuleTestData)
transform.
class := transformation model classNamed: #RBTransformationRuleTestData.
self assert: (class parseTreeFor: #superSends)
equals: (self parseMethod:
'superSends
| rule |
rule := RBParseTreeRewriter new.
rule addSearch: ''super `@message: ``@args''
-> (
[:aNode |
(self class withAllSubclasses
detect: [:each | each includesSelector: aNode selector]
ifNone: [nil]) isNil]
-> ''self `@message: ``@args'').
self rewriteUsing: rule').
self assert: (class parseTreeFor: #checkMethod:)
equals: (self parseMethod:
'checkMethod: aSmalllintContext
self class: aSmalllintContext selectedClass.
(rewriteRule executeTree: aSmalllintContext parseTree) ifTrue:
[(RecursiveSelfRule executeTree: rewriteRule tree initialAnswer: false) ifFalse:
[builder
compile: rewriteRule tree printString
in: self class
classified: aSmalllintContext protocols]]')
]