author | Jan Vrany <jan.vrany@labware.com> |
Wed, 23 Dec 2020 08:46:20 +0000 | |
changeset 10 | 1fa4cd506c87 |
parent 9 | d64df1abdf2a |
permissions | -rw-r--r-- |
9 | 1 |
" |
2 |
COPYRIGHT (c) 2020 LabWare |
|
3 |
" |
|
4 |
"{ Package: 'stx:goodies/ring/core/tests' }" |
|
5 |
||
6 |
"{ NameSpace: Smalltalk }" |
|
7 |
||
8 |
RGAbstractReadOnlyBackendTest subclass:#RGReadOnlyImageBackendTest |
|
9 |
instanceVariableNames:'' |
|
10 |
classVariableNames:'' |
|
11 |
poolDictionaries:'' |
|
12 |
category:'Ring-Tests-Core' |
|
13 |
! |
|
14 |
||
15 |
RGReadOnlyImageBackendTest comment:'' |
|
16 |
! |
|
17 |
||
18 |
!RGReadOnlyImageBackendTest class methodsFor:'documentation'! |
|
19 |
||
20 |
copyright |
|
21 |
" |
|
22 |
COPYRIGHT (c) 2020 LabWare |
|
23 |
||
24 |
||
25 |
" |
|
26 |
! ! |
|
27 |
||
28 |
!RGReadOnlyImageBackendTest methodsFor:'accessing'! |
|
29 |
||
30 |
newEnvironment |
|
31 |
||
32 |
| env | |
|
33 |
||
34 |
env := RGEnvironment unnamed. |
|
35 |
env backend: (RGReadOnlyImageBackend for: env). |
|
36 |
||
37 |
^ env |
|
38 |
! |
|
39 |
||
40 |
testDefaultEnvironmentContent |
|
41 |
||
42 |
| env | |
|
43 |
||
44 |
env := RGEnvironment unnamed. |
|
45 |
env backend: (RGReadOnlyImageBackend for: env). |
|
46 |
||
47 |
self testDefaultContentFor: env. |
|
48 |
||
49 |
||
50 |
||
51 |
||
52 |
! ! |
|
53 |
||
54 |
!RGReadOnlyImageBackendTest methodsFor:'error handling'! |
|
55 |
||
56 |
testEmptyLayout |
|
57 |
||
58 |
| env | |
|
59 |
||
60 |
env := RGEnvironment new. |
|
61 |
env backend: (RGReadOnlyImageBackend for: env). |
|
62 |
||
63 |
self should: [EmptyLayout instance asRingMinimalDefinitionIn: env] raise: Error. |
|
64 |
! |
|
65 |
||
66 |
testLayouts |
|
67 |
||
68 |
| env layout | |
|
69 |
||
70 |
env := RGEnvironment new. |
|
71 |
env backend: (RGReadOnlyImageBackend for: env). |
|
72 |
||
73 |
layout := (ByteString asRingMinimalDefinitionIn: env) layout. |
|
74 |
self assert: layout isLayout. |
|
75 |
self assert: layout isByteLayout. |
|
76 |
||
77 |
layout := (WordArray asRingMinimalDefinitionIn: env) layout. |
|
78 |
self assert: layout isLayout. |
|
79 |
self assert: layout isWordLayout. |
|
80 |
||
81 |
layout := (CompiledMethod asRingMinimalDefinitionIn: env) layout. |
|
82 |
self assert: layout isLayout. |
|
83 |
self assert: layout isCompiledMethodLayout. |
|
84 |
||
85 |
layout := (CompiledMethod asRingMinimalDefinitionIn: env) layout. |
|
86 |
self assert: layout isLayout. |
|
87 |
self assert: layout isCompiledMethodLayout. |
|
88 |
||
89 |
layout := (SmallInteger asRingMinimalDefinitionIn: env) layout. |
|
90 |
self assert: layout isLayout. |
|
91 |
self assert: layout isImmediateLayout. |
|
92 |
||
93 |
layout := (Ephemeron asRingMinimalDefinitionIn: env) layout. |
|
94 |
self assert: layout isLayout. |
|
95 |
self assert: layout isEphemeronLayout. |
|
96 |
||
97 |
layout := (Object asRingMinimalDefinitionIn: env) layout. |
|
98 |
self assert: layout isLayout. |
|
99 |
self assert: layout isFixedLayout. |
|
100 |
||
101 |
layout := (Array asRingMinimalDefinitionIn: env) layout. |
|
102 |
self assert: layout isLayout. |
|
103 |
self assert: layout isVariableLayout. |
|
104 |
||
105 |
layout := (WeakArray asRingMinimalDefinitionIn: env) layout. |
|
106 |
self assert: layout isLayout. |
|
107 |
self assert: layout isWeakLayout. |
|
108 |
||
109 |
||
110 |
! |
|
111 |
||
112 |
testProtocols |
|
113 |
| env1 point method method2 protocol protocol2 | |
|
114 |
env1 := RGEnvironment new. |
|
115 |
env1 backend: (RGReadOnlyImageBackend for: env1). |
|
116 |
||
117 |
point := Point asRingMinimalDefinitionIn: env1. |
|
118 |
self assert: point protocols notEmpty. |
|
119 |
protocol := point protocols detect: [ :each | each = 'accessing' ]. |
|
120 |
self assert: protocol isSymbol. |
|
121 |
||
122 |
method := Point >> #x asRingMinimalDefinitionIn: env1. |
|
123 |
protocol := method protocol. |
|
124 |
method2 := Point >> #y asRingMinimalDefinitionIn: env1. |
|
125 |
protocol2 := method2 protocol. |
|
126 |
||
127 |
self assert: protocol identicalTo: protocol2. |
|
128 |
self assert: protocol isSymbol. |
|
129 |
self assert: protocol equals: 'accessing'. |
|
130 |
||
131 |
self should: [ (Protocol name: 'aProtocol') asRingMinimalDefinitionIn: RGEnvironment new ] raise: Error |
|
132 |
! |
|
133 |
||
134 |
testTraitAlias |
|
135 |
| env traitAlias | |
|
136 |
env := RGEnvironment new. |
|
137 |
env backend: (RGReadOnlyImageBackend for: env). |
|
138 |
||
139 |
traitAlias := MOPTestClassD traitComposition transformations first asRingMinimalDefinitionIn: env. |
|
140 |
self assert: traitAlias isTraitAlias. |
|
141 |
self assert: traitAlias subject name equals: #Trait2. |
|
142 |
self assert: traitAlias aliases size equals: 1. |
|
143 |
self assert: traitAlias aliases first key identicalTo: #c3. |
|
144 |
self assert: traitAlias aliases first value identicalTo: #c2 |
|
145 |
! |
|
146 |
||
147 |
testTraitExclusions |
|
148 |
||
149 |
| env traitExclusion | |
|
150 |
||
151 |
env := RGEnvironment new. |
|
152 |
env backend: (RGReadOnlyImageBackend for: env). |
|
153 |
||
154 |
traitExclusion := (MOPTestClassB traitComposition transformations second) asRingMinimalDefinitionIn: env. |
|
155 |
self assert: traitExclusion isTraitExclusion. |
|
156 |
self assert: traitExclusion subject name equals: #Trait2. |
|
157 |
self assert: traitExclusion exclusions size equals: 1. |
|
158 |
self assert: traitExclusion exclusions first equals: #c. |
|
159 |
||
160 |
||
161 |
||
162 |
||
163 |
! |
|
164 |
||
165 |
testUnknownSlots |
|
166 |
||
167 |
| env slot | |
|
168 |
||
169 |
env := RGEnvironment new. |
|
170 |
env backend: (RGReadOnlyImageBackend for: env). |
|
171 |
||
172 |
slot := (SlotExamplePerson slotNamed: #directedMovies) asRingMinimalDefinitionIn: env. |
|
173 |
self assert: slot isSlot. |
|
174 |
self assert: slot name equals: #directedMovies. |
|
175 |
self assert: slot expression equals: 'ToManyRelationSlot inverse: #director inClass: #SlotExampleMovie'. |
|
176 |
self assert: slot parent isLayout. |
|
177 |
self assert: slot parent isFixedLayout. |
|
178 |
self assert: slot parent parent name equals: #SlotExamplePerson. |
|
179 |
||
180 |
||
181 |
! ! |
|
182 |
||
183 |
!RGReadOnlyImageBackendTest methodsFor:'tests'! |
|
184 |
||
185 |
backendClass |
|
186 |
||
187 |
^ RGReadOnlyImageBackend |
|
188 |
! |
|
189 |
||
190 |
testBehavior |
|
191 |
| env1 point point2 object method | |
|
192 |
env1 := RGEnvironment new. |
|
193 |
env1 backend: (RGReadOnlyImageBackend for: env1). |
|
194 |
||
195 |
point := Point asRingMinimalDefinitionIn: env1. |
|
196 |
"different access method" |
|
197 |
point2 := env1 ask behaviors detect: [ :each | each name == #Point ]. |
|
198 |
object := Object asRingMinimalDefinitionIn: env1. |
|
199 |
method := Point >> #x asRingMinimalDefinitionIn: env1. |
|
200 |
||
201 |
self assert: point identicalTo: point2. |
|
202 |
self assert: point superclass identicalTo: object. |
|
203 |
self assert: point identicalTo: method parent. |
|
204 |
||
205 |
self assert: point unresolvedProperties size equals: 0. |
|
206 |
self assert: point ask localMethods size equals: Point localMethods size |
|
207 |
! |
|
208 |
||
209 |
testBehaviorLocalMethods |
|
210 |
||
211 |
| env1 point selectors | |
|
212 |
||
213 |
env1 := RGEnvironment new. |
|
214 |
env1 backend: (RGReadOnlyImageBackend for: env1). |
|
215 |
||
216 |
point := Point asRingMinimalDefinitionIn: env1. |
|
217 |
||
218 |
self assert: point ask localMethods size equals: Point localMethods size. |
|
219 |
self assert: (point ask localMethods |
|
220 |
allSatisfy: [:each | each isKindOf: RGMethod]). |
|
221 |
selectors := point ask localMethods collect: [ :each | each ask selector ]. |
|
222 |
self assert: (selectors allSatisfy: [:each | each isSymbol]). |
|
223 |
self assert: selectors asSortedCollection equals: Point localSelectors asSortedCollection. |
|
224 |
||
225 |
||
226 |
! |
|
227 |
||
228 |
testClassComment |
|
229 |
||
230 |
| env comment | |
|
231 |
||
232 |
env := RGEnvironment new. |
|
233 |
env backend: (RGReadOnlyImageBackend for: env). |
|
234 |
||
235 |
comment := (Point asRingMinimalDefinitionIn: env) comment. |
|
236 |
||
237 |
comment content notEmpty. |
|
238 |
comment author notEmpty. |
|
10
1fa4cd506c87
core: use `Timestamp` instead of (Pharo) `DateAndTime`
Jan Vrany <jan.vrany@labware.com>
parents:
9
diff
changeset
|
239 |
comment time > Timestamp epoch. |
1fa4cd506c87
core: use `Timestamp` instead of (Pharo) `DateAndTime`
Jan Vrany <jan.vrany@labware.com>
parents:
9
diff
changeset
|
240 |
comment time <= Timestamp now. |
9 | 241 |
|
242 |
||
243 |
! |
|
244 |
||
245 |
testClassVariable |
|
246 |
| env classVariable | |
|
247 |
env := RGEnvironment new. |
|
248 |
env backend: (RGReadOnlyImageBackend for: env). |
|
249 |
||
250 |
classVariable := (UIManager classVariableNamed: #Default) asRingMinimalDefinitionIn: env. |
|
251 |
self assert: classVariable isClassVariable. |
|
252 |
self assert: classVariable name equals: #Default. |
|
253 |
self assert: classVariable parent name equals: #UIManager |
|
254 |
! |
|
255 |
||
256 |
testDefinitionsIdentity |
|
257 |
| env1 | |
|
258 |
env1 := RGEnvironment new. |
|
259 |
env1 backend: (RGReadOnlyImageBackend for: env1). |
|
260 |
||
261 |
self assert: (Object >> #isRGObject asRingMinimalDefinitionIn: env1) identicalTo: (Object >> #isRGObject asRingMinimalDefinitionIn: env1). |
|
262 |
||
263 |
self assert: (Object >> #isRGObject asRingMinimalDefinitionIn: env1) parent identicalTo: (Object >> #isRGObject asRingMinimalDefinitionIn: env1) parent |
|
264 |
! |
|
265 |
||
266 |
testGlobalVariable |
|
267 |
| env real globalVariable | |
|
268 |
env := RGEnvironment new. |
|
269 |
env backend: (RGReadOnlyImageBackend for: env). |
|
270 |
||
271 |
real := Smalltalk globals associations detect: [ :each | each key = #Smalltalk ]. |
|
272 |
globalVariable := real asRingMinimalDefinitionIn: env. |
|
273 |
||
274 |
self assert: globalVariable name equals: #Smalltalk |
|
275 |
! |
|
276 |
||
277 |
testMethod |
|
278 |
| env method | |
|
279 |
env := RGEnvironment new. |
|
280 |
env backend: (RGReadOnlyImageBackend for: env). |
|
281 |
||
282 |
method := Point >> #x asRingMinimalDefinitionIn: env. |
|
283 |
||
284 |
self assert: method author notEmpty. |
|
10
1fa4cd506c87
core: use `Timestamp` instead of (Pharo) `DateAndTime`
Jan Vrany <jan.vrany@labware.com>
parents:
9
diff
changeset
|
285 |
self assert: (method time <= Timestamp now). |
9 | 286 |
self assert: method selector equals: #x. |
287 |
self assert: (method package isRGObject and: [ method package isPackage ]). |
|
288 |
self assert: method package name equals: 'Kernel'. |
|
289 |
self assert: method package identicalTo: method parent package. |
|
290 |
self assert: method sourceCode equals: (Point >> #x) sourceCode. |
|
291 |
self assert: method ast equals: (Point >> #x) ast |
|
292 |
! |
|
293 |
||
294 |
testSlots |
|
295 |
||
296 |
| env slot | |
|
297 |
||
298 |
env := RGEnvironment new. |
|
299 |
env backend: (RGReadOnlyImageBackend for: env). |
|
300 |
||
301 |
slot := (Point slotNamed: #x) asRingMinimalDefinitionIn: env. |
|
302 |
self assert: slot isSlot. |
|
303 |
self assert: slot name equals: #x. |
|
304 |
self assert: slot parent isLayout. |
|
305 |
self assert: slot parent isFixedLayout. |
|
306 |
self assert: slot parent parent name equals: #Point. |
|
307 |
||
308 |
! ! |
|
309 |