author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 31 Aug 2015 14:01:56 +0100 | |
changeset 3 | ed5aae792d24 |
parent 2 | e439b82dda7d |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/ring/tests' }" |
2 |
||
3 |
"{ NameSpace: Smalltalk }" |
|
4 |
||
5 |
TestCase subclass:#RGClassDefinitionTest |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Ring-Core-Kernel-Tests' |
|
10 |
! |
|
11 |
||
12 |
RGClassDefinitionTest comment:'SUnit tests for class definitions' |
|
13 |
! |
|
14 |
||
15 |
!RGClassDefinitionTest methodsFor:'testing'! |
|
16 |
||
17 |
testAddingMethods |
|
18 |
| newMethod newClass | |
|
19 |
||
20 |
newClass:= RGClassDefinition named: #OrderedCollection. |
|
21 |
newMethod:= (RGMethodDefinition named: #add:) |
|
22 |
parent: newClass; |
|
23 |
protocol: 'adding'; |
|
24 |
sourceCode: 'add: newObject |
|
25 |
^self addLast: newObject'. |
|
26 |
||
27 |
self assert: (newMethod isMetaSide not). |
|
28 |
self assert: (newClass hasMethods not). |
|
29 |
||
30 |
newClass addMethod: newMethod. |
|
31 |
newClass addSelector: #size |
|
32 |
classified: 'accessing' |
|
33 |
sourced: 'fakeMethod |
|
34 |
^lastIndex - firstIndex + 1'. |
|
35 |
||
36 |
self assert: (newClass hasMethods). |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
37 |
self assert: (newClass selectors size == 2). |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
38 |
self assert: (newClass selectors includesAll: #(add: size)). |
0 | 39 |
self assert: (newClass includesSelector: #add:). |
40 |
self assert: ((newClass methodNamed: #add:) = newMethod). |
|
41 |
self assert: (newClass methods size = 2). |
|
42 |
self assert: (newClass selectors size = 2). |
|
43 |
self assert: (newClass allSelectors size = 2). "no hierarchy" |
|
44 |
||
45 |
newMethod:= newClass methodNamed: #size. |
|
46 |
self assert: (newMethod parent = newClass). |
|
47 |
||
48 |
self assert: ((newClass compiledMethodNamed: #size) notNil). |
|
49 |
self assert: ((newClass compiledMethodNamed: #fakeMethod) isNil) |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
50 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
51 |
"Modified: / 29-08-2015 / 08:04:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 52 |
! |
53 |
||
54 |
testAsClassDefinition |
|
55 |
| newClass | |
|
56 |
||
57 |
newClass:= OrderedCollection asRingDefinition. |
|
58 |
||
59 |
self assert: (newClass isRingObject). |
|
60 |
self assert: (newClass isClass). |
|
61 |
self assert: (newClass name == #OrderedCollection). |
|
62 |
self assert: (newClass category notNil). |
|
63 |
self assert: (newClass superclassName notNil). |
|
64 |
||
65 |
self assert: (newClass theMetaClass isRingObject). |
|
66 |
self assert: (newClass theMetaClass isClass). |
|
67 |
! |
|
68 |
||
69 |
testAsClassDefinition2 |
|
70 |
||
71 |
| newClass | |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
72 |
newClass:= Class asRingDefinition. |
0 | 73 |
|
74 |
self assert: (newClass isRingObject). |
|
75 |
self assert: (newClass isClass). |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
76 |
self assert: (newClass name == #Class). |
0 | 77 |
self assert: (newClass category notNil). |
78 |
self assert: (newClass superclassName notNil). |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
79 |
"/ self assert: (newClass traitCompositionSource = 'TClass'). |
0 | 80 |
|
81 |
self assert: (newClass theMetaClass isRingObject). |
|
82 |
self assert: (newClass theMetaClass isClass). |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
83 |
"/ self assert: (newClass theMetaClass traitCompositionSource = 'TClass classTrait'). |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
84 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
85 |
"Modified: / 29-08-2015 / 08:05:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 86 |
! |
87 |
||
88 |
testAsClassDefinitionSourceDefinition |
|
89 |
||
90 |
| newClass | |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
91 |
newClass:= Class asRingDefinition. |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
92 |
self assert: (newClass definitionSource = '"{ Package: ''stx:libbasic'' }" |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
93 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
94 |
"{ NameSpace: Smalltalk }" |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
95 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
96 |
ClassDescription subclass:#Class |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
97 |
instanceVariableNames:''name category classvars comment subclasses classFilename package |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
98 |
revision environment signature attributes'' |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
99 |
classVariableNames:''DefaultCategoryForSTV DefaultCategoryForVAGE |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
100 |
DefaultCategoryForDolphin ValidateSourceOnlyOnce ValidatedClasses |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
101 |
SubclassCacheSequenceNumber |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
102 |
DefaultCategoryForUncategorizedClasses |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
103 |
DefaultCategoryForUndeclaredClasses'' |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
104 |
poolDictionaries:'''' |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
105 |
category:''Kernel-Classes'' |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
106 |
'). |
0 | 107 |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
108 |
self assert: (newClass theMetaClass definitionSource= 'Class class instanceVariableNames:'''' |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
109 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
110 |
" |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
111 |
No other class instance variables are inherited by this class. |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
112 |
" |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
113 |
'). |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
114 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
115 |
"Modified (format): / 29-08-2015 / 08:07:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 116 |
! |
117 |
||
118 |
testAsRingDefinition |
|
119 |
self assert: OrderedCollection asRingDefinition asRingDefinition isRingObject |
|
120 |
! |
|
121 |
||
122 |
testClassEquality |
|
123 |
| newClass | |
|
124 |
||
125 |
self assert: OrderedCollection asRingDefinition = OrderedCollection asRingDefinition. |
|
126 |
||
127 |
newClass := (OrderedCollection asRingDefinition) |
|
128 |
category: #Kernel. |
|
129 |
self assert: (OrderedCollection asRingDefinition = newClass) |
|
130 |
! |
|
131 |
||
132 |
testExistingClass |
|
133 |
| newClass metaClass | |
|
134 |
||
135 |
newClass:= RGClassDefinition named: #OrderedCollection. |
|
136 |
self assert: (newClass isClass). |
|
137 |
self assert: (newClass isDefined). |
|
138 |
self assert: (newClass realClass = OrderedCollection). |
|
139 |
self assert: (newClass isMeta not). |
|
140 |
||
141 |
newClass withMetaclass. |
|
142 |
self assert: (newClass hasMetaclass). |
|
143 |
metaClass:= newClass theMetaClass. |
|
144 |
self assert: (metaClass isMeta). |
|
145 |
self assert: (metaClass name = 'OrderedCollection class'). |
|
146 |
self assert: (metaClass theNonMetaClass = newClass). |
|
147 |
self assert: (metaClass realClass = OrderedCollection class). |
|
148 |
! |
|
149 |
||
3
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
150 |
testNewClass |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
151 |
| newClass | |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
152 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
153 |
newClass:= RGClassDefinition newClass. |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
154 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
155 |
self assert: (newClass isRingObject). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
156 |
self assert: (newClass isClass). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
157 |
self assert: (newClass name isNil). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
158 |
self assert: (newClass theMetaClass notNil). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
159 |
self assert: (newClass theMetaClass isMetaclass). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
160 |
self assert: (newClass theMetaClass name isNil). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
161 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
162 |
newClass name: 'NewClass'. |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
163 |
self assert: (newClass name = 'NewClass'). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
164 |
self assert: (newClass theMetaClass name = 'NewClass class'). |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
165 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
166 |
"Created: / 29-08-2015 / 12:02:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
167 |
! |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2
diff
changeset
|
168 |
|
0 | 169 |
testNonExistingClass |
170 |
| newClass | |
|
171 |
||
172 |
newClass:= RGClassDefinition named: #Connection. |
|
173 |
self assert: (newClass isClass). |
|
174 |
self assert: (newClass instanceVariables isEmpty). |
|
175 |
self assert: (newClass classVariables isEmpty). |
|
176 |
self assert: (newClass sharedPools isEmpty). |
|
177 |
self assert: (newClass hasMetaclass not). |
|
178 |
self assert: (newClass hasComment not). |
|
179 |
self assert: (newClass hasStamp not). |
|
180 |
self assert: (newClass parent = Smalltalk globals). |
|
181 |
self assert: (newClass package isNil). |
|
182 |
self assert: (newClass category isNil). |
|
183 |
self assert: (newClass hasMethods not). |
|
184 |
self assert: (newClass hasSuperclass not). |
|
185 |
self assert: (newClass hasTraitComposition not). |
|
186 |
self assert: (newClass isDefined not). |
|
187 |
self assert: (newClass hasProtocols not). |
|
188 |
||
189 |
||
190 |
! |
|
191 |
||
192 |
testReadFrom |
|
193 |
"self debug: #testReadFrom" |
|
194 |
||
195 |
||
196 |
| st rg | |
|
197 |
rg := Point asRingDefinition. |
|
198 |
st := String streamContents: [:s | |
|
199 |
rg storeOn: s. |
|
200 |
s contents]. |
|
201 |
self assert: (Object readFrom: st) = rg. |
|
202 |
||
203 |
rg := Point class asRingDefinition. |
|
204 |
st := String streamContents: [:s | |
|
205 |
rg storeOn: s. |
|
206 |
s contents]. |
|
207 |
self assert: (Object readFrom: st) = rg |
|
208 |
! |
|
209 |
||
210 |
testRemovingMethods |
|
211 |
| newMethod newClass | |
|
212 |
||
213 |
newClass:= RGClassDefinition named: #OrderedCollection. |
|
214 |
newMethod:= (RGMethodDefinition named: #add:) |
|
215 |
parent: newClass; |
|
216 |
protocol: 'adding'; |
|
217 |
sourceCode: 'add: newObject |
|
218 |
^self addLast: newObject'. |
|
219 |
self assert: (newClass hasMethods not). |
|
220 |
||
221 |
newClass addMethod: newMethod. |
|
222 |
newClass addSelector: #size |
|
223 |
classified: 'accessing' |
|
224 |
sourced: 'size |
|
225 |
^ lastIndex - firstIndex + 1'. |
|
226 |
||
227 |
self assert: (newClass selectors = #(add: size)). |
|
228 |
newClass removeSelector: #join:. |
|
229 |
self assert: (newClass selectors = #(add: size)). |
|
230 |
newClass removeMethod: newMethod. |
|
231 |
self assert: ((newClass includesSelector: #add:) not). |
|
232 |
newClass removeSelector: #size. |
|
233 |
self assert: (newClass hasMethods not). |
|
234 |
! |
|
235 |
||
236 |
testStoreOn |
|
237 |
"self debug: #testStoreOn" |
|
238 |
||
239 |
||
240 |
| st | |
|
241 |
st := String streamContents: [:s | |
|
242 |
||
243 |
(Point) asRingDefinition storeOn: s. |
|
244 |
s contents]. |
|
245 |
self assert: st = '(RGClassDefinition named: #Point)'. |
|
246 |
||
247 |
st := String streamContents: [:s | |
|
248 |
||
249 |
(Point class) asRingDefinition storeOn: s. |
|
250 |
s contents]. |
|
251 |
self assert: st = '((RGMetaclassDefinition named: #''Point class'') baseClass:(RGClassDefinition named: #Point))' |
|
252 |
! |
|
253 |
||
254 |
testWithCategory |
|
255 |
| newClass | |
|
256 |
||
257 |
newClass:= (RGClassDefinition named: #Object) |
|
258 |
category: 'Kernel-Objects'; |
|
259 |
yourself. |
|
260 |
||
261 |
self assert: (newClass package isNil). |
|
262 |
self assert: (newClass category = 'Kernel-Objects'). |
|
263 |
! |
|
264 |
||
265 |
testWithClassInstanceVariables |
|
266 |
| newClass metaClass classInstVar | |
|
267 |
||
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
268 |
newClass:= RGClassDefinition named: #GenericException. |
0 | 269 |
newClass withMetaclass. |
270 |
metaClass:= newClass theMetaClass. |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
271 |
metaClass addInstanceVariables: #(NotifierString). |
0 | 272 |
|
273 |
self assert: (metaClass instanceVariables size = 1). |
|
274 |
self assert: (metaClass instVarNames size = 1). |
|
275 |
self assert: (metaClass allInstVarNames size = 1). |
|
276 |
||
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
277 |
classInstVar:= metaClass instanceVariableNamed: #NotifierString. |
0 | 278 |
self assert: (classInstVar notNil). |
279 |
self assert: (classInstVar parent = metaClass). |
|
280 |
self assert: (classInstVar isClassInstanceVariable). |
|
281 |
self assert: (classInstVar isVariable). |
|
282 |
self assert: (classInstVar parentName = metaClass name). |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
283 |
self assert: (classInstVar realClass = GenericException class). |
0 | 284 |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
285 |
metaClass removeInstVarNamed: #NotifierString. |
0 | 286 |
self assert: (metaClass instanceVariables isEmpty). |
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
287 |
self assert: ((metaClass instanceVariableNamed: #NotifierString) isNil). |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
288 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
289 |
"Modified: / 29-08-2015 / 10:28:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 290 |
! |
291 |
||
292 |
testWithClassVariables |
|
293 |
| newClass classVar | |
|
294 |
||
295 |
newClass:= (RGClassDefinition named: #Object) |
|
296 |
addClassVariables: #(DependentsFields); |
|
297 |
addClassVarNamed: #FakeVariable; |
|
298 |
yourself. |
|
299 |
||
300 |
self assert: (newClass classVariables size = 2). |
|
301 |
self assert: (newClass classVarNames size = 2). |
|
302 |
self assert: (newClass allClassVarNames size = 2). "no hierarchy" |
|
303 |
||
304 |
classVar:= newClass classVarNamed: #DependentsFields. |
|
305 |
self assert: (classVar notNil). |
|
306 |
self assert: (classVar isClassVariable). |
|
307 |
self assert: (classVar isVariable). |
|
308 |
self assert: (classVar parent = newClass). |
|
309 |
self assert: (classVar parentName == newClass name). |
|
310 |
self assert: (classVar realClass = Object). |
|
311 |
||
312 |
newClass withMetaclass. |
|
313 |
self assert: (newClass theMetaClass allClassVarNames size = 2). |
|
314 |
||
315 |
newClass removeClassVarNamed: #DependentsFields. |
|
316 |
self assert: (newClass classVariables size = 1). |
|
317 |
! |
|
318 |
||
319 |
testWithComment |
|
320 |
| newClass newComment | |
|
321 |
||
322 |
newClass:= RGClassDefinition named: #Object. |
|
323 |
newComment:= RGCommentDefinition new |
|
324 |
parent: newClass; |
|
325 |
content: 'This is a comment for test'; |
|
326 |
stamp: 'VeronicaUquillas 3/22/2011 14:51'; |
|
327 |
yourself. |
|
328 |
newClass comment: newComment. |
|
329 |
||
330 |
self assert: (newClass hasComment). |
|
331 |
self assert: (newClass hasStamp). |
|
332 |
self assert: (newClass = newComment parent). |
|
333 |
self assert: (newComment content = 'This is a comment for test'). |
|
334 |
self assert: (newComment author = 'VeronicaUquillas'). |
|
335 |
self assert: (newComment timeStamp = '3/22/2011 14:51' asDateAndTime). |
|
336 |
||
337 |
newClass comment: nil. |
|
338 |
self assert: (newClass hasComment not). |
|
339 |
||
340 |
newClass comment: 'This is a comment for test'; |
|
341 |
stamp: 'VeronicaUquillas 3/22/2011 14:51'. |
|
342 |
||
343 |
self assert: (newClass comment isRingObject). |
|
344 |
! |
|
345 |
||
346 |
testWithDefaultNamespace |
|
347 |
| newClass | |
|
348 |
||
349 |
newClass:= RGClassDefinition named: #Object. |
|
350 |
||
351 |
self assert: (newClass parent = Smalltalk globals). |
|
352 |
self assert: (newClass realClass = Object). |
|
353 |
! |
|
354 |
||
355 |
testWithInstanceVariables |
|
356 |
| newClass instVar | |
|
357 |
||
358 |
newClass:= RGClassDefinition named: #OrderedCollection. |
|
359 |
newClass addInstanceVariables: #(array firstIndex). |
|
360 |
newClass addInstVarNamed: #lastIndex. |
|
361 |
||
362 |
self assert: (newClass instanceVariables size = 3). |
|
363 |
self assert: (newClass instVarNames size = 3). |
|
364 |
self assert: (newClass allInstVarNames size = 3). |
|
365 |
||
366 |
instVar:= newClass instanceVariableNamed: #firstIndex. |
|
367 |
self assert: (instVar notNil). |
|
368 |
self assert: (instVar parent = newClass). |
|
369 |
self assert: (instVar isInstanceVariable). |
|
370 |
self assert: (instVar isVariable). |
|
371 |
self assert: (instVar parentName == newClass name). |
|
372 |
self assert: (instVar realClass = OrderedCollection). |
|
373 |
||
374 |
newClass removeInstVarNamed: #array. |
|
375 |
self assert: (newClass instanceVariables size = 2). |
|
376 |
self assert: ((newClass instanceVariableNamed: #array) isNil). |
|
377 |
||
378 |
! |
|
379 |
||
380 |
testWithPoolDictionaries |
|
381 |
| newClass poolVar | |
|
382 |
||
383 |
newClass:= (RGClassDefinition named: #Text) |
|
384 |
addSharedPoolNamed: #TextConstants; |
|
385 |
yourself. |
|
386 |
||
387 |
self assert: (newClass sharedPools size = 1). |
|
388 |
self assert: (newClass sharedPoolNames size = 1). |
|
389 |
self assert: (newClass allSharedPools size = 1). "no hierarchy" |
|
390 |
self assert: (newClass allSharedPoolNames size = 1). |
|
391 |
||
392 |
poolVar:= newClass sharedPoolNamed: #TextConstants. |
|
393 |
self assert: (poolVar notNil). |
|
394 |
self assert: (poolVar isPoolVariable). |
|
395 |
self assert: (poolVar isVariable). |
|
396 |
self assert: (poolVar parent = newClass). |
|
397 |
self assert: (poolVar parentName == newClass name). |
|
398 |
self assert: (poolVar realClass = Text). |
|
399 |
||
400 |
newClass withMetaclass. |
|
401 |
self assert: (newClass theMetaClass allSharedPoolNames size = 1). |
|
402 |
||
403 |
newClass removeSharedPoolNamed: #TextConstants. |
|
404 |
self assert: (newClass sharedPools isEmpty). |
|
405 |
! |
|
406 |
||
407 |
testWithProtocols |
|
408 |
| newMethod newClass | |
|
409 |
||
410 |
newClass:= RGClassDefinition named: #OrderedCollection. |
|
411 |
newMethod:= (RGMethodDefinition named: #add:) |
|
412 |
parent: newClass; |
|
413 |
protocol: 'adding'; |
|
414 |
sourceCode: 'add: newObject |
|
415 |
^self addLast: newObject'. |
|
416 |
||
417 |
newClass addMethod: newMethod. |
|
418 |
newClass addProtocol: 'accessing'. |
|
419 |
||
420 |
self assert: (newClass hasProtocols). |
|
421 |
self assert: (newClass protocols size = 2). |
|
422 |
self assert: (newClass includesProtocol: 'accessing'). |
|
423 |
self assert: ((newClass methodsInProtocol: 'adding') size = 1). |
|
424 |
self assert: ((newClass methodsInProtocol: 'accessing') isEmpty) |
|
425 |
! |
|
426 |
||
427 |
testWithSuperclass |
|
428 |
| newClass supClass | |
|
429 |
||
430 |
supClass:= (RGClassDefinition named: #Object) |
|
431 |
superclassName: #ProtoObject; |
|
432 |
yourself. |
|
433 |
||
434 |
self assert: (supClass hasSuperclass not). |
|
435 |
self assert: (supClass superclassName == #ProtoObject). "kept as annotation" |
|
436 |
self assert: (supClass annotations size = 1). |
|
437 |
||
438 |
newClass := (RGClassDefinition named: #OrderedCollection) superclass: supClass. |
|
439 |
self assert: (newClass superclass = supClass). |
|
440 |
self assert: (newClass superclassName == #Object). |
|
441 |
self assert: (newClass withAllSuperclasses size = 2). |
|
442 |
self assert: (newClass allSuperclasses size = 1). |
|
443 |
||
444 |
self assert: (supClass subclasses size = 1). |
|
445 |
self assert: (supClass withAllSubclasses size = 2). |
|
446 |
self assert: (supClass allSubclasses size = 1). |
|
447 |
! ! |
|
448 |