/
ClyClassDefinitionEditorToolMorphTest.class.st
213 lines (181 loc) · 6.13 KB
/
ClyClassDefinitionEditorToolMorphTest.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"
A ClyClassDefinitionEditorToolMorphTest is a test class for testing the behavior of ClyClassDefinitionEditorToolMorph
"
Class {
#name : #ClyClassDefinitionEditorToolMorphTest,
#superclass : #TestCase,
#instVars : [
'classDefinitionEditor',
'editor',
'className',
'context',
'oldString'
],
#category : #'Calypso-SystemTools-Core-Tests-Editors-Classes'
}
{ #category : #asserting }
ClyClassDefinitionEditorToolMorphTest >> assertResultCompilationDidntChange [
"if the string changed, then there is a syntax error
It may be because it was treated as a method"
self assert: oldString equals: editor textMorph text string
]
{ #category : #asserting }
ClyClassDefinitionEditorToolMorphTest >> assertResultCompilationEquals: aString [
self assert: editor textMorph text string equals: aString
]
{ #category : #helper }
ClyClassDefinitionEditorToolMorphTest >> checkClassDoesntExists [
(self class environment classNamed: className) ifNotNil: [ self error: 'Need to rename test class to not override existing class' ].
]
{ #category : #helper }
ClyClassDefinitionEditorToolMorphTest >> classExists [
^ (self class environment classNamed: className) isNotNil
]
{ #category : #helper }
ClyClassDefinitionEditorToolMorphTest >> compileString: aString [
oldString := aString.
editor textMorph setTextWith: aString.
editor applyChanges.
]
{ #category : #helper }
ClyClassDefinitionEditorToolMorphTest >> deleteClassIfExists [
| instaledClass |
instaledClass := self class environment classNamed: className.
instaledClass ifNil:[ ^ self ].
instaledClass removeFromSystem
]
{ #category : #running }
ClyClassDefinitionEditorToolMorphTest >> setUp [
| browser containerTab methodGroupQuery |
super setUp.
className := #MyClass.
context := MockClyFullBrowserClassContext new.
methodGroupQuery := MockMethodGroupQuery new.
browser := (ClyFullBrowserBlockingUI on: ClyNavigationEnvironment currentImage)
methodGroupQuery: methodGroupQuery;
yourself.
containerTab := MockClyContainerTab new.
editor := ClyClassDefinitionEditorToolMorph new
browser: nil;
context: context;
containerTab: containerTab;
browser: browser;
setUpModelFromContext;
build;
yourself.
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptASyntaxErroredClassDefinitionFailsWithoutTryingToCompileAsMethod [
"Not sure what a syntax error look like for a shift class builder definition.
Open to ideas"
self error.
self compileString:
'Object subclass: #' , className , '
instanceVariableNames: ''#''
classVariableNames: ''''
package: ''Calypso-SystemQueries-Tests'''.
self assertResultCompilationEquals:
'Object subclass: #MyClass
instanceVariableNames: ''''
classVariableNames: ''''
package: ''Calypso-SystemQueries-Tests'''
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptASyntaxErroredFluidClassDefinitionFailsWithoutTryingToCompileAsMethod [
self compileString:
'Object << #', className , '
slots: { #s #s };
package: ''Calypso-SystemTools-Core-Tests'''.
self assertResultCompilationEquals:
'Object << #MyClass
slots: { #s # End of statement expected ->s };
package: ''Calypso-SystemTools-Core-Tests'''
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptASyntaxErroredMethodShouldFailCompilationAsMethod [
"failing compilation of a method definition & a fluid class definition should treat their own syntax errors"
self compileString: 'banana^'.
self assertResultCompilationEquals:
'banana^ Variable or expression expected ->'
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptASyntaxErroredTraitDefinitionFailsWithoutTryingToCompileAsMethod [
self compileString:
'Object << #', className , '
slots: { #s #s };
package: ''Calypso-SystemTools-Core-Tests'''.
self assertResultCompilationEquals:
'Object << #MyClass
slots: { #s # End of statement expected ->s };
package: ''Calypso-SystemTools-Core-Tests'''.
self error: #todo
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptAWellWrittenClassDefinitionRegistersIt [
self checkClassDoesntExists.
[
self compileString:
'Object subclass: #' , className , '
instanceVariableNames: ''''
classVariableNames: ''''
package: ''Calypso-SystemTools-Core-Tests'''.
self assert: self classExists.
self assertResultCompilationDidntChange.
] ensure: [ self deleteClassIfExists ].
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptAWellWrittenFluidClassDefinitionRegistersIt [
self checkClassDoesntExists.
[
self compileString:
'Object << #', className , '
package: ''Calypso-SystemTools-Core-Tests'''.
self assert: self classExists.
self assertResultCompilationDidntChange.
] ensure: [ self deleteClassIfExists ].
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptAWellWrittenMethodRegistersIt [
| selector |
selector := #banana.
(context class class lookupSelector: selector) ifNotNil: [ self error: 'I might overide an important behavior' ].
[
self compileString:
selector , '
^ 1'.
self assert: (context class class methodDict includes: selector) isNotNil.
self assertResultCompilationDidntChange.
] ensure: [ context class class removeSelector: selector ].
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testAcceptAWellWrittenTraitDefinitionRegistersIt [
self error: #todo.
self compileString: 'Object << #MyClass
slots: { #s #s };
package: ''Calypso-SystemQueries-Tests'''.
editor applyChanges .
]
{ #category : #test }
ClyClassDefinitionEditorToolMorphTest >> testRedefineAClassShouldRedefineIt [
| newClass oldUIManager |
self checkClassDoesntExists.
self compileString:
'Object << #' , className , '
package: ''Calypso-SystemQueries-Tests'''.
oldUIManager := UIManager default.
[
UIManager default: NonInteractiveUIManager new.
[
self compileString:
'Object << #' , className , '
slots: {#s};
package: ''Calypso-SystemQueries-Tests'''.
]
on: ProvideAnswerNotification
do:[ :e | e resume: true ]
]
ensure: [ UIManager default: oldUIManager ].
newClass := self class environment classNamed: #MyClass.
[ self assert: newClass allSlots size equals: 1 ]
ensure: [ self deleteClassIfExists ]
]