-
Notifications
You must be signed in to change notification settings - Fork 11
/
MirrorTesting.ns
819 lines (750 loc) · 28.3 KB
/
MirrorTesting.ns
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
Newspeak3
'Root'
class MirrorTesting usingPlatform: p minitest: m model: md = (|
private ObjectMirror = p mirrors ObjectMirror.
private ClassMirror = p mirrors ClassMirror.
private Map = p collections Map.
private Set = p collections Set.
private TestContext = m TestContext.
private model = md.
|) (
public class ClassDeclarationMirrorTests = TestBase () (
public testClassDeclarationMirrorEnclosingClass = (
| mirror mirror2 |
mirror:: (ClassMirror reflecting: model Klass) mixin declaration.
mirror2:: (ObjectMirror reflecting: model) getClass mixin declaration.
assert: mirror enclosingClass equals: mirror2.
assert: mirror2 enclosingClass equals: nil.
)
public testClassDeclarationMirrorEquality = (
| mirror mirror2 |
mirror:: (ClassMirror reflecting: model Klass) mixin declaration.
mirror2:: (ClassMirror reflecting: model Klass) mixin declaration.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
deny: mirror equals: mirror instanceSide.
deny: mirror equals: mirror classSide.
deny: mirror equals: mirror header.
mirror:: (ObjectMirror reflecting: model) getClass mixin declaration.
mirror2:: (ObjectMirror reflecting: model) getClass mixin declaration.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
deny: mirror equals: mirror instanceSide.
deny: mirror equals: mirror classSide.
deny: mirror equals: mirror header.
mirror:: (ClassMirror reflecting: model Klass) mixin declaration.
mirror2:: (ObjectMirror reflecting: model) getClass mixin declaration.
deny: mirror equals: mirror2.
)
public testClassDeclarationMirrorName = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin declaration.
assert: mirror name equals: 'Klass'. (* Not MirrorTestingModel`Klass *)
mirror:: (ObjectMirror reflecting: model) getClass mixin declaration.
assert: mirror name equals: 'MirrorTestingModel'.
)
public testIsKindOfClassDeclarationMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfClassDeclarationMirror.
deny: classMirror isKindOfClassDeclarationMirror.
deny: instanceMixinMirror isKindOfClassDeclarationMirror.
assert: classDeclarationMirror isKindOfClassDeclarationMirror.
deny: classHeaderMirror isKindOfClassDeclarationMirror.
deny: classMixinMirror isKindOfClassDeclarationMirror.
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfClassDeclarationMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfClassDeclarationMirror].
classMirror nestedClasses do:
[:nestedClassMirror | assert: nestedClassMirror isKindOfClassDeclarationMirror].
)
) : (
TEST_CONTEXT = ()
)
public class ClassHeaderMirrorTests = TestBase () (
public testClassHeaderMirrorEquality = (
| mirror mirror2 |
mirror:: (ClassMirror reflecting: model Klass) mixin declaration header.
mirror2:: (ClassMirror reflecting: model Klass) mixin declaration header.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
mirror:: (ObjectMirror reflecting: model) getClass mixin declaration header.
mirror2:: (ObjectMirror reflecting: model) getClass mixin declaration header.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
mirror:: (ClassMirror reflecting: model Klass) mixin declaration header.
mirror2:: (ObjectMirror reflecting: model) getClass mixin declaration header.
deny: mirror equals: mirror2.
)
public testClassHeaderMirrorName = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin declaration header.
assert: mirror name equals: 'Klass'. (* Not MirrorTestingModel`Klass *)
mirror:: (ObjectMirror reflecting: model) getClass mixin declaration header.
assert: mirror name equals: 'MirrorTestingModel'.
)
public testIsKindOfClassHeaderMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfClassHeaderMirror.
deny: classMirror isKindOfClassHeaderMirror.
deny: instanceMixinMirror isKindOfClassHeaderMirror.
deny: classDeclarationMirror isKindOfClassHeaderMirror.
assert: classHeaderMirror isKindOfClassHeaderMirror.
deny: classMixinMirror isKindOfClassHeaderMirror.
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfClassHeaderMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfClassHeaderMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfClassHeaderMirror].
)
) : (
TEST_CONTEXT = ()
)
public class ClassMirrorTests = TestBase () (
classOf: classMirror = (
^(ObjectMirror reflecting: classMirror reflectee) getClass
)
public testClassMirrorEnclosingObject = (
assert: (ClassMirror reflecting: model Klass) enclosingObject
equals: (ObjectMirror reflecting: model).
assert: (ObjectMirror reflecting: model) getClass enclosingObject
equals: (ObjectMirror reflecting: nil).
(* :todo: Cases with generalized mixin application *)
)
public testClassMirrorEquality = (
| mirror mirror2 |
mirror:: ClassMirror reflecting: model Klass.
mirror2:: (ObjectMirror reflecting: (model Klass factory: 2)) getClass.
assert: mirror equals: mirror2.
assert: mirror2 equals: mirror.
assert: mirror hash equals: mirror2 hash.
deny: mirror equals: mirror mixin.
deny: mirror2 equals: mirror2 mixin.
deny: mirror equals: nil.
deny: mirror2 equals: nil.
deny: nil equals: mirror.
deny: nil equals: mirror2.
mirror:: (ObjectMirror reflecting: model) getClass.
mirror2:: (ClassMirror reflecting: model Klass) enclosingObject getClass.
assert: mirror equals: mirror2.
assert: mirror2 equals: mirror.
assert: mirror hash equals: mirror2 hash.
deny: mirror equals: mirror mixin.
deny: mirror2 equals: mirror2 mixin.
deny: mirror equals: nil.
deny: mirror2 equals: nil.
deny: nil equals: mirror.
deny: nil equals: mirror2.
mirror:: ClassMirror reflecting: model Klass.
mirror2:: (ObjectMirror reflecting: model) getClass.
deny: mirror equals: mirror2.
deny: mirror equals: mirror mixin.
deny: mirror2 equals: mirror2 mixin.
deny: mirror equals: nil.
deny: mirror2 equals: nil.
deny: nil equals: mirror.
deny: nil equals: mirror2.
(* Same mixin, same superclass, different enclosing object. *)
mirror:: ClassMirror reflecting: (model Klass factory: 2) Nested.
mirror2:: ClassMirror reflecting: (model Klass factory: 2) Nested.
assert: mirror mixin equals: mirror2 mixin.
deny: mirror equals: mirror2.
deny: mirror2 equals: mirror.
)
public testClassMirrorIsMeta = (
| mirror mirror2 |
mirror:: ClassMirror reflecting: model Klass.
deny: mirror isMeta.
mirror:: (ObjectMirror reflecting: model Klass) getClass.
assert: mirror isMeta.
mirror:: (ObjectMirror reflecting: model) getClass.
deny: mirror isMeta.
mirror:: (ClassMirror reflecting: model Klass) enclosingObject getClass.
deny: mirror isMeta.
mirror:: ClassMirror reflecting: self class yourclass.
assert: mirror isMeta.
)
public testClassMirrorMethods = (
| object mirror |
(* Fails because of all the stuff from ImplementationBase in Squeak *)
object:: (ClassMirror reflecting: Object) mixin.
mirror:: ClassMirror reflecting: model Klass.
assertSet: ((mirror methods reject: [:method | method definingMixin = object])
collect: [:method | method name])
equals: {'superMethod'. '>>>'. 'defaultMethod'. 'keyword:method:'. 'privateMethod'. 'protectedMethod'. 'publicMethod'}.
mirror:: classOf: mirror.
mirror methods.
)
public testClassMirrorName = (
(* :todo: Should we answer the name with or without the hash?
| mirror |
mirror:: ClassMirror reflecting: model Klass.
assert: mirror name equals: 'Klass'.
mirror:: (ObjectMirror reflecting: (model Klass factory: 2)) getClass.
assert: mirror name equals: 'Klass'.
mirror:: (ObjectMirror reflecting: model) getClass.
assert: mirror name equals: 'MirrorTestingModel'.
mirror:: (ClassMirror reflecting: model Klass) enclosingObject getClass.
assert: mirror name equals: 'MirrorTestingModel'.
mirror:: ClassMirror reflecting: model Klass.
assert: mirror name equals: 'Klass'.
mirror:: (ObjectMirror reflecting: model) getClass.
assert: mirror name equals: 'MirrorTestingModel'.
mirror:: ClassMirror reflecting: (model Klass factory: 2) Nested.
assert: mirror name equals: 'Nested'.
mirror:: ClassMirror reflecting: (model Klass factory: 2) Nested.
assert: mirror name equals: 'Nested'. *)
)
public testClassMirrorNestedClasses = (
| mirror |
mirror:: ClassMirror reflecting: model Klass.
assertSet: (mirror nestedClasses collect: [:klass | klass name])
equals: {'SuperNestedClass'. 'DefaultNestedClass'. 'Nested'. 'PrivateNestedClass'. 'ProtectedNestedClass'. 'PublicNestedClass'}.
mirror:: classOf: mirror.
mirror nestedClasses.
)
public testClassMirrorNonBehavior = (
should: [ClassMirror reflecting: 'Not a behavior'] signal: Error
)
public testClassMirrorSlots = (
| mirror |
mirror:: ClassMirror reflecting: model Klass.
assertList: (mirror slots collect: [:slot | slot name])
equals: {'superSlot'. 'publicSlot'. 'protectedSlot'. 'defaultSlot'. 'privateSlot'. 'mutableSlot'. 'immutableSlot'. 'uninitializedSlot'}.
mirror:: classOf: mirror.
mirror slots.
)
public testClassMirrorSuperclass = (
assert: (ClassMirror reflecting: model Klass) superclass
equals: (ClassMirror reflecting: model SuperKlass).
assert: (ClassMirror reflecting: model SuperKlass) superclass
equals: (ClassMirror reflecting: Object).
assert: (ClassMirror reflecting: Object) superclass
equals: nil. (* fails in Squeak because the superclass of Object is ImplementationBase *)
(* :todo: Cases with generalized mixin application *)
)
public testIsKindOfClassMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfClassMirror.
assert: classMirror isKindOfClassMirror.
deny: instanceMixinMirror isKindOfClassMirror.
deny: classDeclarationMirror isKindOfClassMirror.
deny: classHeaderMirror isKindOfClassMirror.
deny: classMixinMirror isKindOfClassMirror.
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfClassMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfClassMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfClassMirror].
)
public testMetaRelationships = (
|
mClassMirrorTests = ClassMirror reflecting: class.
mObject = ClassMirror reflecting: Object.
mClass = (classOf: mClassMirrorTests) superclass.
mMetaclass = classOf: (classOf: mClassMirrorTests).
|
assert: [mObject mixin name = 'Object' or: [mObject mixin name = '_Object']].
assert: mClass mixin name equals: 'Class'.
assert: mMetaclass mixin name equals: 'Metaclass'.
assert: [mClass superclass = mObject
or: [mClass superclass superclass = mObject]]
description: 'Class superclass [superclass] = Object'.
assert: (classOf: mObject) superclass equals: mClass.
assert: (classOf: mClass) superclass equals: mClass.
assert: (classOf: mClassMirrorTests) superclass equals: mClass.
assert: (classOf: mMetaclass) superclass equals: mClass.
assert: (classOf: (classOf: mObject)) equals: mMetaclass.
assert: (classOf: (classOf: mClass)) equals: mMetaclass.
assert: (classOf: (classOf: mMetaclass)) equals: mMetaclass.
assert: (classOf: (classOf: mClassMirrorTests)) equals: mMetaclass.
)
public testClassMirrorLazySlots = (
| mirror |
mirror:: ClassMirror reflecting: model Klass.
assertList: (mirror lazySlots collect: [:slot | slot name])
equals: {'lazyPublicSlot'. 'lazyPrivateSlot'. 'lazyProtectedSlot'}.
mirror:: classOf: mirror.
mirror lazySlots.
)
) : (
TEST_CONTEXT = ()
public yourclass = (
^self class
)
)
class ErrorOnEquals = () (
public = other = (
^Error new signal
)
public class = (
^Error new signal
)
public hash = (
^Error new signal
)
) : (
)
public class MethodMirrorTests = TestBase () (
public testMethodMirrorAccessModifier = (
| methods |
methods:: (ClassMirror reflecting: model Klass) mixin methods.
assert: (in: methods findMirrorNamed: 'defaultMethod') accessModifier equals: #protected.
assert: (in: methods findMirrorNamed: 'privateMethod') accessModifier equals: #private.
assert: (in: methods findMirrorNamed: 'protectedMethod') accessModifier equals: #protected.
assert: (in: methods findMirrorNamed: 'publicMethod') accessModifier equals: #public.
)
public testMethodMirrorEquality = (
| mirror mirror2 mirror3 methods |
(* Different applications of the same mixin. *)
mirror:: ClassMirror reflecting: (model Klass factory: 2) Nested.
mirror:: in: mirror methods findMirrorNamed: 'nestedMethod'.
mirror2:: ClassMirror reflecting: (model Klass factory: 2) Nested.
mirror2:: in: mirror2 methods findMirrorNamed: 'nestedMethod'.
mirror3:: (ClassMirror reflecting: model Klass).
mirror3:: in: mirror3 nestedClasses findMirrorNamed: 'Nested'.
mirror3:: in: mirror3 instanceSide methods findMirrorNamed: 'nestedMethod'.
assert: mirror equals: mirror2.
assert: mirror2 equals: mirror3.
assert: mirror3 equals: mirror.
assert: mirror hash equals: mirror2 hash.
assert: mirror2 hash equals: mirror3 hash.
assert: mirror3 hash equals: mirror hash.
(* Different methods. *)
methods:: (ClassMirror reflecting: model Klass) mixin methods.
mirror:: in: methods findMirrorNamed: 'protectedMethod'.
mirror2:: in: methods findMirrorNamed: 'privateMethod'.
mirror3:: in: methods findMirrorNamed: 'publicMethod'.
deny: mirror equals: mirror2.
deny: mirror2 equals: mirror3.
deny: mirror3 equals: mirror.
deny: mirror equals: nil.
deny: nil equals: mirror.
)
public testIsKindOfMethodMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfMethodMirror.
deny: classMirror isKindOfMethodMirror.
deny: instanceMixinMirror isKindOfMethodMirror.
deny: classDeclarationMirror isKindOfMethodMirror.
deny: classHeaderMirror isKindOfMethodMirror.
deny: classMixinMirror isKindOfMethodMirror.
classMirror lazySlots do:
[:slotMirror | deny: slotMirror isKindOfMethodMirror].
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfMethodMirror].
classMirror methods do:
[:methodMirror | assert: methodMirror isKindOfMethodMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfMethodMirror].
)
) : (
TEST_CONTEXT = ()
)
public class MixinMirrorTests = TestBase () (
public testIsKindOfMixinMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfMixinMirror.
deny: classMirror isKindOfMixinMirror.
assert: instanceMixinMirror isKindOfMixinMirror.
deny: classDeclarationMirror isKindOfMixinMirror.
deny: classHeaderMirror isKindOfMixinMirror.
assert: classMixinMirror isKindOfMixinMirror.
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfMixinMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfMixinMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfMixinMirror].
)
public testMixinMirrorDeclaration = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assert: mirror declaration name equals: 'Klass'.
assert: mirror declaration instanceSide equals: mirror.
deny: mirror declaration equals: mirror. (* Even though they have the same reflectee. *)
mirror:: (ObjectMirror reflecting: model Klass) getClass mixin.
assert: mirror declaration name equals: 'Klass'.
assert: mirror declaration classSide equals: mirror.
deny: mirror declaration equals: mirror.
)
public testMixinMirrorEnclosingMixin = (
| mirror mirror2 |
mirror:: (ClassMirror reflecting: model Klass) mixin.
mirror2:: (ObjectMirror reflecting: model) getClass mixin.
assert: mirror enclosingMixin equals: mirror2.
assert: mirror2 enclosingMixin equals: nil.
)
public testMixinMirrorEquality = (
| mirror mirror2 |
mirror:: (ClassMirror reflecting: model Klass) mixin.
mirror2:: (ClassMirror reflecting: model Klass) mixin.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
mirror:: (ObjectMirror reflecting: model) getClass mixin.
mirror2:: (ObjectMirror reflecting: model) getClass mixin.
assert: mirror equals: mirror2.
assert: mirror hash equals: mirror2 hash.
mirror:: (ClassMirror reflecting: model Klass) mixin.
mirror2:: (ObjectMirror reflecting: model) getClass mixin.
deny: mirror equals: mirror2.
)
public testMixinMirrorIsMeta = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
deny: mirror isMeta.
mirror:: mirror declaration classSide.
assert: mirror isMeta.
)
public testMixinMirrorMethods = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assertSet: (mirror methods collect: [:method | method name])
equals: {'>>>'. 'defaultMethod'. 'keyword:method:'. 'privateMethod'. 'protectedMethod'. 'publicMethod'}.
mirror methods do: [:method | assert: method definingMixin equals: mirror].
mirror:: mirror declaration classSide.
assertSet: (mirror methods collect: [:method | method name])
equals: {'classMethod'}.
mirror methods do: [:method | assert: method definingMixin equals: mirror].
)
public testMixinMirrorName = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assert: mirror name equals: 'Klass'. (* Not MirrorTestingModel`Klass *)
mirror:: mirror declaration classSide.
assert: mirror name equals: 'Klass class'.
mirror:: (ObjectMirror reflecting: model) getClass mixin.
assert: mirror name equals: 'MirrorTestingModel'.
mirror:: mirror declaration classSide.
assert: mirror name equals: 'MirrorTestingModel class'.
)
public testMixinMirrorNestedClasses = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assertSet: (mirror nestedClasses collect: [:klass | klass name])
equals: {'DefaultNestedClass'. 'Nested'. 'PrivateNestedClass'. 'ProtectedNestedClass'. 'PublicNestedClass'}.
mirror nestedClasses do: [:klass | assert: klass definingMixin equals: mirror].
mirror:: mirror declaration classSide.
assertSet: (mirror nestedClasses collect: [:klass | klass name])
equals: {}.
mirror nestedClasses do: [:klass | assert: klass definingMixin equals: mirror].
)
public testMixinMirrorSlots = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assertList: (mirror slots collect: [:slot | slot name])
equals: {'publicSlot'. 'protectedSlot'. 'defaultSlot'. 'privateSlot'. 'mutableSlot'. 'immutableSlot'. 'uninitializedSlot'}.
mirror slots do: [:slot | assert: slot definingMixin equals: mirror].
mirror:: mirror declaration classSide.
assertList: (mirror slots collect: [:slot | slot name])
equals: {}.
mirror slots do: [:slot | assert: slot definingMixin equals: mirror].
)
public testMixinMirrorLazySlots = (
| mirror |
mirror:: (ClassMirror reflecting: model Klass) mixin.
assertList: (mirror lazySlots collect: [:slot | slot name])
equals: {'lazyPublicSlot'. 'lazyPrivateSlot'. 'lazyProtectedSlot'}.
mirror lazySlots do: [:slot | assert: slot definingMixin equals: mirror].
mirror:: mirror declaration classSide.
assertList: (mirror lazySlots collect: [:slot | slot name])
equals: {}.
)
) : (
TEST_CONTEXT = ()
)
public class ObjectMirrorTests = TestBase () (
class A = (
|
public a1
public a2
|
) (
foo = ( ^'A' )
) : (
)
class B = A () (
foo = ( ^'B' )
) : (
)
class C = B (
|
public c1
public c2
|
) (
foo = ( ^'C' )
) : (
)
public testIsKindOfObjectMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
assert: objectMirror isKindOfObjectMirror.
deny: classMirror isKindOfObjectMirror.
deny: instanceMixinMirror isKindOfObjectMirror.
deny: classDeclarationMirror isKindOfObjectMirror.
deny: classHeaderMirror isKindOfObjectMirror.
deny: classMixinMirror isKindOfObjectMirror.
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfObjectMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfObjectMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfObjectMirror].
)
public testObjectMirrorEquality = (
| a b |
a:: ErrorOnEquals new.
b:: ErrorOnEquals new.
assert: (ObjectMirror reflecting: a) equals: (ObjectMirror reflecting: a).
assert: (ObjectMirror reflecting: a) hash equals: (ObjectMirror reflecting: a) hash.
deny: (ObjectMirror reflecting: a) equals: (ObjectMirror reflecting: b).
deny: (ObjectMirror reflecting: a) equals: nil.
deny: nil equals: (ObjectMirror reflecting: a).
)
public testObjectMirrorEvaluate = (
| c mirror thread |
c:: C new.
mirror:: ObjectMirror reflecting: c.
thread:: mirror evaluate: 'foo'.
assert: thread isFulfilled.
assert: thread result reflectee equals: 'C'.
should: [mirror evaluate: '--parse--error--'] signal: Error.
)
public testObjectMirrorEvaluateEmpty = (
| c mirror thread |
c:: C new.
mirror:: ObjectMirror reflecting: c.
thread:: mirror evaluate: ''.
assert: thread isFulfilled.
assert: thread result reflectee equals: c.
)
public testObjectMirrorEvaluateWithScope = (
| c mirror scope thread |
c:: C new.
c a1: 3.
c c1: 4.
mirror:: ObjectMirror reflecting: c.
scope:: Map new.
scope at: #w put: (ObjectMirror reflecting: 10).
thread:: mirror evaluate: 'a1 + c1 + w' with: scope.
assert: thread isFulfilled.
assert: thread result reflectee equals: 17.
)
public testObjectMirrorGetClass = (
| a |
a:: ErrorOnEquals new.
assert: (ObjectMirror reflecting: a) getClass equals: (ClassMirror reflecting: ErrorOnEquals).
assert: (ObjectMirror reflecting: a) getClass reflectee equals: ErrorOnEquals.
)
public testObjectMirrorGetSlot = (
| c mirror result |
c:: C new.
c a1: 10.
c a2: 20.
c c1: 30.
c c2: 40.
mirror:: ObjectMirror reflecting: c.
result:: mirror getSlot: #a1.
assert: result reflectee equals: 10.
result:: mirror getSlot: #a2.
assert: result reflectee equals: 20.
result:: mirror getSlot: #c1.
assert: result reflectee equals: 30.
result:: mirror getSlot: #c2.
assert: result reflectee equals: 40.
)
public testObjectMirrorPerform = (
)
public testObjectMirrorReflectee = (
| obj |
obj:: Object new.
assert: (ObjectMirror reflecting: obj) reflectee equals: obj.
)
public testObjectMirrorSetClass = (
)
public testObjectMirrorSetClassShapeChange = (
)
public testObjectMirrorSetSlot = (
| c mirror result |
c:: C new.
c a1: 10.
c a2: 20.
c c1: 30.
c c2: 40.
mirror:: ObjectMirror reflecting: c.
mirror setSlot: #a1 to: 100.
assert: c a1 equals: 100.
assert: c a2 equals: 20.
assert: c c1 equals: 30.
assert: c c2 equals: 40.
mirror setSlot: #a2 to: 200.
assert: c a1 equals: 100.
assert: c a2 equals: 200.
assert: c c1 equals: 30.
assert: c c2 equals: 40.
mirror setSlot: #c1 to: 300.
assert: c a1 equals: 100.
assert: c a2 equals: 200.
assert: c c1 equals: 300.
assert: c c2 equals: 40.
mirror setSlot: #c2 to: 400.
assert: c a1 equals: 100.
assert: c a2 equals: 200.
assert: c c1 equals: 300.
assert: c c2 equals: 400.
)
public testObjectMirrorSetSlotImmutable = (
)
) : (
TEST_CONTEXT = ()
)
public class SlotDeclarationMirrorTests = TestBase () (
public testSlotDeclarationMirrorAccessModifier = (
| slots |
slots:: (ClassMirror reflecting: model Klass) mixin slots.
assert: (in: slots findMirrorNamed: 'defaultSlot') accessModifier equals: #protected.
assert: (in: slots findMirrorNamed: 'privateSlot') accessModifier equals: #private.
assert: (in: slots findMirrorNamed: 'protectedSlot') accessModifier equals: #protected.
assert: (in: slots findMirrorNamed: 'publicSlot') accessModifier equals: #public.
)
public testSlotDeclarationMirrorIsMutable = (
| slots |
slots:: (ClassMirror reflecting: model Klass) mixin slots.
assert: (in: slots findMirrorNamed: 'mutableSlot') isMutable.
deny: (in: slots findMirrorNamed: 'immutableSlot') isMutable.
assert: (in: slots findMirrorNamed: 'uninitializedSlot') isMutable.
)
public testIsKindOfLazySlotDeclarationMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
(* Q: Are lazy slots considered slots? Or are they a completely separate kind of thing *)
deny: objectMirror isKindOfLazySlotDeclarationMirror.
deny: classMirror isKindOfLazySlotDeclarationMirror.
deny: instanceMixinMirror isKindOfLazySlotDeclarationMirror.
deny: classDeclarationMirror isKindOfLazySlotDeclarationMirror.
deny: classHeaderMirror isKindOfLazySlotDeclarationMirror.
deny: classMixinMirror isKindOfLazySlotDeclarationMirror.
classMirror lazySlots do:
[:slotMirror | assert: slotMirror isKindOfLazySlotDeclarationMirror].
classMirror slots do:
[:slotMirror | deny: slotMirror isKindOfLazySlotDeclarationMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfLazySlotDeclarationMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfLazySlotDeclarationMirror].
)
public testLazySlotDeclarationMirrorAccessModifier = (
| slots |
slots:: (ClassMirror reflecting: model Klass) mixin lazySlots.
assert: (in: slots findMirrorNamed: 'lazyPrivateSlot') accessModifier equals: #private.
assert: (in: slots findMirrorNamed: 'lazyProtectedSlot') accessModifier equals: #protected.
assert: (in: slots findMirrorNamed: 'lazyPublicSlot') accessModifier equals: #public.
)
public testIsKindOfSlotDeclarationMirror = (
|
objectMirror = ObjectMirror reflecting: model.
classMirror = objectMirror getClass.
instanceMixinMirror = classMirror mixin.
classDeclarationMirror = instanceMixinMirror declaration.
classHeaderMirror = classDeclarationMirror header.
classMixinMirror = classDeclarationMirror classSide.
|
deny: objectMirror isKindOfSlotDeclarationMirror.
deny: classMirror isKindOfSlotDeclarationMirror.
deny: instanceMixinMirror isKindOfSlotDeclarationMirror.
deny: classDeclarationMirror isKindOfSlotDeclarationMirror.
deny: classHeaderMirror isKindOfSlotDeclarationMirror.
deny: classMixinMirror isKindOfSlotDeclarationMirror.
classMirror slots do:
[:slotMirror | assert: slotMirror isKindOfSlotDeclarationMirror].
classMirror lazySlots do:
[:slotMirror | deny: slotMirror isKindOSlotDeclarationMirror].
classMirror methods do:
[:methodMirror | deny: methodMirror isKindOfSlotDeclarationMirror].
classMirror nestedClasses do:
[:nestedClassMirror | deny: nestedClassMirror isKindOfSlotDeclarationMirror].
)
public testLazySlotDeclarationMirrorIsMutable = (
| slots |
slots:: (ClassMirror reflecting: model Klass) mixin lazySlots.
assert: (in: slots findMirrorNamed: 'lazyProtectedSlot') isMutable.
deny: (in: slots findMirrorNamed: 'lazyPublicSlot') isMutable.
deny: (in: slots findMirrorNamed: 'lazyPrivateSlot') isMutable.
)
) : (
TEST_CONTEXT = ()
)
class TestBase = TestContext () (
assertSet: actual equals: expected = (
| missing extra missingString extraString |
missing:: Set new.
missing addAll: expected.
actual do: [:element | missing remove: element ifAbsent: []].
extra:: Set new.
extra addAll: actual.
expected do: [:element | extra remove: element ifAbsent: []].
(missing isEmpty and: [extra isEmpty]) ifTrue: [^self].
missingString: ''.
missing do: [:element | missingString: missingString, ' ', element printString].
extraString: ''.
extra do: [:element | extraString: extraString, ' ', element printString].
failWithMessage: 'Missing:', missingString, ' Extra:', extraString.
)
in: collection findMirrorNamed: name = (
collection do: [:mirror | mirror name = name ifTrue: [^mirror]].
^nil
)
) : (
)
) : (
)