-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
RBInlineMethodFromComponentTest.class.st
174 lines (166 loc) · 6.29 KB
/
RBInlineMethodFromComponentTest.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
Class {
#name : #RBInlineMethodFromComponentTest,
#superclass : #RBRefactoringTest,
#category : #'Refactoring-Tests-Core'
}
{ #category : #tests }
RBInlineMethodFromComponentTest >> testInlineComponentIntoCascadedMessage [
| refactoring |
self proceedThroughWarning:
[ refactoring := RBInlineMethodFromComponentRefactoring
inline: (self
convertInterval: (35 to: 79)
for: (RBRefactoryTestDataApp sourceCodeAt: #inlineComponent))
inMethod: #inlineComponent
forClass: RBRefactoryTestDataApp.
(refactoring model classNamed: #Behavior)
compile: 'hasImmediateInstances ^self format = 0'
classified: #(#accessing ).
self
setupInlineExpressionFor: refactoring
toReturn: false.
self executeRefactoring: refactoring ].
self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineComponent) = (self parseMethod: 'inlineComponent
| a aBehavior |
a := 5.
aBehavior := a class.
aBehavior superclass.
aBehavior format = 0.
^aBehavior yourself')
]
{ #category : #tests }
RBInlineMethodFromComponentTest >> testInlineComponentMethodMax [
| refactoring |
self proceedThroughWarning:
[ | class |
refactoring := RBInlineMethodFromComponentRefactoring
inline: (self
convertInterval: (47 to: 58)
for: (RBRefactoryTestDataApp sourceCodeAt: #inlineMax))
inMethod: #inlineMax
forClass: RBRefactoryTestDataApp.
self
setupInlineExpressionFor: refactoring
toReturn: true.
class := refactoring model classNamed: #Magnitude.
class
compile: 'max: aMagnitude
"Answer the receiver or the argument, whichever has the greater magnitude."
self > aMagnitude
ifTrue: [^self]
ifFalse: [^aMagnitude]'
classified: #(#accessing ).
self
setupImplementorToInlineFor: refactoring
toReturn: class.
self executeRefactoring: refactoring ].
self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineMax) = (self parseMethod: 'inlineMax
| x y q |
x := 5.
y := 10.
q := x + 1 > y
ifTrue: [x + 1]
ifFalse: [y].
^q')
]
{ #category : #tests }
RBInlineMethodFromComponentTest >> testInlineEmptyComponentMethod [
| refactoring |
self proceedThroughWarning:
[ refactoring := RBInlineMethodFromComponentRefactoring
inline: (self
convertInterval: (35 to: 91)
for: (RBRefactoryTestDataApp sourceCodeAt: #inlineComponent))
inMethod: #inlineComponent
forClass: RBRefactoryTestDataApp.
self
setupInlineExpressionFor: refactoring
toReturn: false.
"The following line is needed because some people implement #yourself themselves."
self
setupImplementorToInlineFor: refactoring
toReturn: (refactoring model classNamed: #Object).
self executeRefactoring: refactoring ].
self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineComponent) = (self parseMethod: 'inlineComponent
| a anObject |
a := 5.
anObject := a class.
anObject superclass.
anObject hasImmediateInstances.
^anObject')
]
{ #category : #'failure tests' }
RBInlineMethodFromComponentTest >> testInlineMethodFromComponentFailure [
self shouldFail: (RBInlineMethodFromComponentRefactoring
inline: (self
convertInterval: (50 to: 64)
for: (RBRefactoryTestDataApp sourceCodeAt: #inlineFailed))
inMethod: #inlineFailed
forClass: RBRefactoryTestDataApp)
]
{ #category : #tests }
RBInlineMethodFromComponentTest >> testModelInlineMethodWithSameVariableNames [
| class refactoring |
model := RBClassModelFactory rbNamespace new.
class := model classNamed: self class name.
class compile: 'a9: a b9: b ^self + a + b' classified: #(#accessing).
(model classNamed: #Object)
compile: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^a a9: b b9: c'
classified: #(#accessing).
self proceedThroughWarning:
[refactoring := RBInlineMethodFromComponentRefactoring
model: model
inline: (72 to: 84)
inMethod: #foo
forClass: (model classNamed: #Object).
self setupInlineExpressionFor: refactoring toReturn: false.
self executeRefactoring: refactoring].
self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo)
= (self
parseMethod: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^a + b + c')
]
{ #category : #tests }
RBInlineMethodFromComponentTest >> testModelInlineMethodWithSameVariableNames1 [
| class refactoring |
model := RBClassModelFactory rbNamespace new.
class := model classNamed: #Rectangle.
class
compile: 'rectangleRelativeTo: aRectangle ^self origin extent: aRectangle extent'
classified: #(#accessing).
(model classNamed: #Object)
compile: 'foo | aRectangle temp | aRectangle := 0@0 corner: 1@1. temp := aRectangle. ^aRectangle rectangleRelativeTo: temp'
classified: #(#accessing).
self proceedThroughWarning:
[refactoring := RBInlineMethodFromComponentRefactoring
model: model
inline: (77 to: 112)
inMethod: #foo
forClass: (model classNamed: #Object).
self setupInlineExpressionFor: refactoring toReturn: false.
self setupImplementorToInlineFor: refactoring toReturn: class.
self executeRefactoring: refactoring].
self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo)
= (self
parseMethod: 'foo | aRectangle temp | aRectangle := 0@0 corner: 1@1. temp := aRectangle. ^aRectangle origin extent: temp extent')
]
{ #category : #tests }
RBInlineMethodFromComponentTest >> testModelInlineMethodWithSameVariableNames2 [
| class refactoring |
model := RBClassModelFactory rbNamespace new.
class := model classNamed: self class name.
class compile: 'a9: a b9: b ^self + a + b' classified: #(#accessing).
(model classNamed: #Object)
compile: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^c a9: b b9: a'
classified: #(#accessing).
self proceedThroughWarning:
[refactoring := RBInlineMethodFromComponentRefactoring
model: model
inline: (72 to: 84)
inMethod: #foo
forClass: (model classNamed: #Object).
self setupInlineExpressionFor: refactoring toReturn: false.
self executeRefactoring: refactoring].
self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo)
= (self
parseMethod: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^c + b + a')
]