-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
BehaviorTest.class.st
258 lines (199 loc) · 7.57 KB
/
BehaviorTest.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
"
SUnit tests for Behavior
"
Class {
#name : #BehaviorTest,
#superclass : #ClassTestCase,
#category : #'Kernel-Tests-Classes'
}
{ #category : #tests }
BehaviorTest >> sampleMessageWithFirstArgument: firstArgument "This is a comment intended to explain arg1"
andInterleavedCommentBeforeSecondArgument: secondArgument [
"This method is here to test a few utilities like formalParametersAt:"
| thisIsAnUnusedTemp |
thisIsAnUnusedTemp := self.
^thisIsAnUnusedTemp
]
{ #category : #tests }
BehaviorTest >> testAllMethods [
| allMethods nonOverridenMethods |
allMethods := IdentitySet new
addAll: Object allMethods;
yourself.
self assert: (allMethods includesAll: Object methods). "We fetch all compiled methods that are not redefined in Object"
nonOverridenMethods := OrderedCollection new.
ProtoObject
selectorsAndMethodsDo: [ :sel :method |
(Object includesSelector: sel)
ifFalse: [ nonOverridenMethods add: method ] ].
self assert: (allMethods includesAll: nonOverridenMethods)
]
{ #category : #tests }
BehaviorTest >> testAllSelectors [
self assert: ProtoObject allSelectors asSet = ProtoObject selectors asSet.
self assert: Object allSelectors asSet = (Object selectors asSet union: ProtoObject selectors).
self assert: (Object allSelectorsBelow: ProtoObject) asSet = (Object selectors) asSet.
]
{ #category : #tests }
BehaviorTest >> testAllSelectorsAbove [
|sels |
sels := Date allSelectorsAbove.
self deny: (sels includes: #mmddyyyy).
self deny: (sels includes: #weekday).
self assert: (sels includes: #at:).
self assert: (sels includes: #cannotInterpret: )
]
{ #category : #tests }
BehaviorTest >> testAllSelectorsAboveUntil [
|sels |
sels := Date allSelectorsAboveUntil: Object..
self deny: (sels includes: #mmddyyyy).
self deny: (sels includes: #weekday).
self assert: (sels includes: #at:).
self deny: (sels includes: #cannotInterpret: )
]
{ #category : #tests }
BehaviorTest >> testBehaviornewnewShouldNotCrash [
Behavior new new.
"still not working correctly but at least does not crash the image"
]
{ #category : #tests }
BehaviorTest >> testBinding [
self assert: Object binding value = Object.
self assert: Object binding key = #Object.
self assert: Object class binding value = Object class.
"returns nil for Metaclasses... like Encoder>>#associationFor:"
self assert: Object class binding key isNil.
]
{ #category : #tests }
BehaviorTest >> testHasAbstractMethods [
self deny: Object hasAbstractMethods.
self deny: Object class hasAbstractMethods.
"Behavior has abstract methods, for example hasTraitComposition, basicLocalSelectors:"
self assert: Behavior hasAbstractMethods.
self deny: Behavior class hasAbstractMethods.
self assert: ObjectLayout hasAbstractMethods.
"ObjectLayout defines methods because its class side contains abstract methods"
self assert: ObjectLayout class hasAbstractMethods.
]
{ #category : #tests }
BehaviorTest >> testIncludesMethod [
self assert: (Object includesMethod: Object>>#halt).
self deny: (Class includesMethod: Object>>#halt).
self assert: (Point includesMethod: Point>>#x).
self deny: (LookupKey includesMethod: Point>>#x).
]
{ #category : #tests }
BehaviorTest >> testIsAbstract [
self deny: Behavior isAbstract.
self deny: Behavior class isAbstract.
self deny: ClassDescription isAbstract.
self deny: ClassDescription class isAbstract.
self deny: Class isAbstract.
self deny: Class class isAbstract.
self deny: Object isAbstract.
self deny: Object class isAbstract.
]
{ #category : #tests }
BehaviorTest >> testIsReferenced [
self assert: Object isReferenced.
self deny: Object class isReferenced
]
{ #category : #tests }
BehaviorTest >> testIsRootInEnvironment [
self assert: ProtoObject isRootInEnvironment.
self deny: Object isRootInEnvironment
]
{ #category : #tests }
BehaviorTest >> testIsUsed [
self assert: Object isUsed.
self assert: Object class isUsed.
]
{ #category : #'tests - queries' }
BehaviorTest >> testMethodsAccessingSlot [
| numberViaSlot numberViaIVar |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
numberViaSlot := (Point methodsAccessingSlot: (Point slotNamed: #x)) size.
numberViaIVar := (Point whichSelectorsAccess: 'x') size.
self assert: numberViaSlot = numberViaIVar.
]
{ #category : #'tests - queries' }
BehaviorTest >> testMethodsReadingSlot [
| numberViaSlot numberViaIVar |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
numberViaSlot := (Point methodsReadingSlot: (Point slotNamed: #x)) size.
numberViaIVar := (Point whichSelectorsRead: 'x') size.
self assert: numberViaSlot = numberViaIVar.
]
{ #category : #'tests - queries' }
BehaviorTest >> testMethodsWritingSlot [
| numberViaSlot numberViaIVar |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
numberViaSlot := (Point methodsWritingSlot: (Point slotNamed: #x)) size.
numberViaIVar := (Point whichSelectorsStoreInto: 'x') size.
self assert: numberViaSlot = numberViaIVar.
]
{ #category : #metrics }
BehaviorTest >> testNumberOfInstanceVariables [
self assert: Object numberOfInstanceVariables equals: 0.
self assert: Point numberOfInstanceVariables equals: 2.
self assert: Metaclass numberOfInstanceVariables equals: 1
]
{ #category : #'tests - properties' }
BehaviorTest >> testPropertyValueAtPut [
| testValue |
testValue := Date today.
self class propertyAt: #testKeySelector put: testValue.
self
assert: (self class propertyAt: #testKeySelector)
equals: testValue.
self class removeProperty: #testKeySelector
]
{ #category : #'tests - properties' }
BehaviorTest >> testRemoveProperty [
self class propertyAt: #testKeySelector put: 1.
self class removeProperty: #testKeySelector.
self assert: (self class propertyAt: #testKeySelector) equals: nil
]
{ #category : #'tests - queries' }
BehaviorTest >> testallMethodsAccessingSlot [
| methods |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
methods := LookupKey allMethodsAccessingSlot: (LookupKey slotNamed: #key).
self assert: (methods includes: (Association >>#key:value:))
]
{ #category : #'tests - queries' }
BehaviorTest >> testallMethodsReadingSlot [
| methods |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
methods := LookupKey allMethodsReadingSlot: (LookupKey slotNamed: #key).
self assert: (methods includes: (Ephemeron >>#mourn))
]
{ #category : #'tests - queries' }
BehaviorTest >> testallMethodsWritingSlot [
| methods |
"Check the source code availability to do not fail on images without sources"
(Point>>#x) hasSourceCode ifFalse: [ ^ self ].
methods := LookupKey allMethodsWritingSlot: (LookupKey slotNamed: #key).
self assert: (methods includes: (Association >>#key:value:))
]
{ #category : #tests }
BehaviorTest >> testallSuperclassesIncluding [
|cls |
cls := ArrayedCollection allSuperclassesIncluding: Collection.
self deny: (cls includes: ArrayedCollection).
self deny: (cls includes: Object).
self assert: (cls includes: Collection).
self assert: (cls includes: SequenceableCollection).
]
{ #category : #tests }
BehaviorTest >> testsourceCodeTemplateFor [
"check for distictive source code templates for class-side and instance-side"
self assert: ((Object sourceCodeTemplate) includesSubstring: 'instance-side message').
self assert: ((Object class sourceCodeTemplate) includesSubstring: 'class-side message')
]