-
Notifications
You must be signed in to change notification settings - Fork 11
/
AccessModifierTesting.ns
900 lines (900 loc) · 27.6 KB
/
AccessModifierTesting.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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
Newspeak3
'Root'
class AccessModifierTesting usingPlatform: platform testFramework: minitest
(* :exemplar: AccessModifierTesting usingPlatform: platform testFramework: ide minitest *) = (|
private TestContext = minitest TestContext.
private ClassMirror = platform mirrors ClassMirror.
private MessageNotUnderstood = platform kernel MessageNotUnderstood.
|) (
public class ClassAccessingTests = TestContext (
(* Try to access classes with different access modifiers, but only via public send.
Class access is implemented via accessor methods - so fetching a class falls back to finding the appropriate method.
All kind of different method sends are already tested in the MethodAcessingTests. *)
|
testSubjects = TestSubjects new.
|) (
public testPrivateClassAccess = (
should: [testSubjects APrivateClass] signal: MessageNotUnderstood.
)
public testProtectedClassAccess = (
should: [testSubjects AProtectedClass] signal: MessageNotUnderstood.
)
public testPublicClassAccess = (
assert: testSubjects APublicClass new ping = #pong.
)
public testPublicClassAccess2 = (
testSubjects AClass
)
) : (
TEST_CONTEXT = ()
)
public class JITTests = TestContext () (
class A = () (
protected foo = (
^'A'
)
) : (
)
class B = A () (
private foo = (
^'B'
)
) : (
)
class C = B () (
public foo = (
^'C'
)
public superFoo = (
^super foo
)
) : (
)
class D1 = C () (
public foo = (
^'D1'
)
) : (
)
class D2 = C () (
public foo = (
^'D2'
)
) : (
)
class D3 = C () (
public foo = (
^'D3'
)
) : (
)
class ImplicitReceiverMNU = ImplicitReceiverMNUSuper (
) (
private result = (
^#ImplicitReceiverMNU.
)
public sendImplicitReceiverFoo = (
^foo
)
) : (
)
class ImplicitReceiverMNUSuper = (
) (
doesNotUnderstand: message = (
^result
)
private result = (
^#ImplicitReceiverMNUSuper.
)
) : (
)
class OuterMNU = OuterMNUSuper (
) (
public class Inner = () (
public sendOuterFoo = (
^outer OuterMNU foo
)
) : (
)
private result = (
^#OuterMNU.
)
) : (
)
class OuterMNUSuper = (
) (
doesNotUnderstand: message = (
^result (* This implicit receiver send will crash if the method receiver is wrong. *)
)
private result = (
^#OuterMNUSuper.
)
) : (
)
class SelfMNU = SelfMNUSuper (
) (
private result = (
^#SelfMNU
)
public sendSelfFoo = (
^self foo
)
) : (
)
class SelfMNUSuper = (
) (
doesNotUnderstand: message = (
^result
)
private result = (
^#SelfMNUSuper
)
) : (
)
class SuperMNU = SuperMNUSuper (
) (
private result = (
^#SuperMNU
)
public sendSuperFoo = (
^super foo
)
) : (
)
class SuperMNUSuper = (
) (
doesNotUnderstand: message = (
^result
)
private result = (
^#SuperMNUSuper
)
) : (
)
public testImplicitReceiverMNU = (
| aImplicitReceiverMnu = ImplicitReceiverMNU new. |
10 timesRepeat:
[assert: aImplicitReceiverMnu sendSuperFoo equals: #ImplicitReceiverMNUSuper].
)
public testOuterMNU = (
| anInner = OuterMNU new Inner new. |
10 timesRepeat:
[assert: anInner sendOuterFoo equals: #OuterMNUSuper].
)
public testPolymorphicSuper = (
| d1 = D1 new. d2 = D2 new. d3 = D3 new. |
10 timesRepeat:
[assert: d1 superFoo equals: 'A'.
assert: d2 superFoo equals: 'A'.
assert: d3 superFoo equals: 'A'].
)
public testSelfMNU = (
| aSelfMnu = SelfMNU new. |
10 timesRepeat:
[assert: aSelfMnu sendSelfFoo equals: #SelfMNUSuper].
)
public testSuperMNU = (
| aSuperMnu = SuperMNU new. |
10 timesRepeat:
[assert: aSuperMnu sendSuperFoo equals: #SuperMNUSuper].
)
) : (
TEST_CONTEXT = ()
)
public class MethodAccessingTests = TestContext (
(* Test access to methods with different access modifiers *)
|
testSubjects = TestSubjects new.
|) (
public testDefaultImplicitReceiverSend = (
(* send a message via an implicitReceiverSend which goes to a method with default access modifier *)
assert: testSubjects ASubClass new ASubInnerClass new defaultImplicitReceiverSend = #defaultImplicitReceiverTarget.
)
public testDefaultImplicitReceiverSendWithInheritance = (
(* send a message via implicitReceiverSend which goes to a method with default access modifier with inheritance *)
assert: testSubjects ASubClass new defaultImplicitReceiverSendWithInheritance = #defaultMethod.
)
public testDefaultOuterSend = (
(* send a message via an outerSend which goes to a method with default access modifier *)
assert: testSubjects AClass new AInnerClass new outerDefaultMethod = #defaultMethod.
)
public testDefaultOuterSendWithInheritance = (
(* send a message via an outerSend which goes to a method with default access modifier via inheritance *)
assert: testSubjects ASubClass new ASubInnerClass new defaultOuterSendWithInheritance = #defaultMethod.
)
public testDefaultPublicSend = (
(* send a message via publicSend which goes to a method with default access modifier *)
should: [testSubjects AClass new defaultMethod] signal: MessageNotUnderstood.
)
public testDefaultPublicSendWithInheritance = (
(* send a message via publicSend which goes to a method with default access modifier in the super chain *)
should: [testSubjects ASubClass new defaultMethod] signal: MessageNotUnderstood.
)
public testDefaultSelfSend = (
(* send a message via selfSend which goes to a method with default access modifier *)
assert: testSubjects AClass new selfDefaultMethod = #defaultMethod.
)
public testDefaultSelfSendWithInheritance = (
(* send a message via selfSend which goes to a method with default access modifier in the super chain *)
assert: testSubjects ASubClass new selfDefaultMethod = #defaultMethod.
)
public testDefaultSuperSend = (
(* send a message via superSend which goes to a method with default access modifier *)
assert: testSubjects ASubClass new superDefaultMethod = #defaultMethod.
)
public testImplicitPrivateOverriddenByProtected = (
assert: testSubjects AClass new AInnerClass new implicitPrivateOverriddenByProtected
equals: #private.
assert: testSubjects ASubClass new AInnerClass new implicitPrivateOverriddenByProtected
equals: #private.
)
public testImplicitPrivateOverriddenByPublic = (
assert: testSubjects AClass new AInnerClass new implicitPrivateOverriddenByPublic
equals: #private.
assert: testSubjects ASubClass new AInnerClass new implicitPrivateOverriddenByPublic
equals: #private.
)
public testImplicitProtectedOverriddenByPrivate = (
assert: testSubjects AClass new AInnerClass new implicitProtectedOverriddenByPrivate
equals: #protected.
assert: testSubjects ASubClass new AInnerClass new implicitProtectedOverriddenByPrivate
equals: #protected.
)
public testImplicitProtectedOverriddenByPublic = (
assert: testSubjects AClass new AInnerClass new implicitProtectedOverriddenByPublic
equals: #protected.
assert: testSubjects ASubClass new AInnerClass new implicitProtectedOverriddenByPublic
equals: #public.
)
public testImplicitPublicOverriddenByPrivate = (
assert: testSubjects AClass new AInnerClass new implicitPublicOverriddenByPrivate
equals: #public.
assert: testSubjects ASubClass new AInnerClass new implicitPublicOverriddenByPrivate
equals: #public.
)
public testImplicitPublicOverriddenByProtected = (
assert: testSubjects AClass new AInnerClass new implicitPublicOverriddenByProtected
equals: #public.
assert: testSubjects ASubClass new AInnerClass new implicitPublicOverriddenByProtected
equals: #protected.
)
public testObjectEncapsulationPrivate = (
| sharedClass = testSubjects AClass. |
should: [ sharedClass new callPrivateMethodOn: sharedClass new ]
signal: MessageNotUnderstood.
)
public testObjectEncapsulationProtected = (
| sharedClass = testSubjects AClass. |
should: [ sharedClass new callProtectedMethodOn: sharedClass new ]
signal: MessageNotUnderstood.
)
public testOrdinaryPrivateOverriddenByProtected = (
should: [testSubjects ASubClass new privateOverriddenByProtected]
signal: MessageNotUnderstood.
)
public testOrdinaryPrivateOverriddenByPublic = (
assert: testSubjects ASubClass new privateOverriddenByPublic
equals: #public.
)
public testOrdinaryProtectedOverriddenByPrivate = (
should: [testSubjects ASubClass new protectedOverriddenByPrivate]
signal: MessageNotUnderstood.
)
public testOrdinaryProtectedOverriddenByPublic = (
assert: testSubjects ASubClass new protectedOverriddenByPublic
equals: #public.
)
public testOrdinaryPublicOverriddenByPrivate = (
assert: testSubjects ASubClass new publicOverriddenByPrivate
equals: #public.
)
public testOrdinaryPublicOverriddenByProtected = (
should: [testSubjects ASubClass new publicOverriddenByProtected]
signal: MessageNotUnderstood.
)
public testOuterPrivateOverriddenByProtected = (
assert: testSubjects AClass new AInnerClass new outerPrivateOverriddenByProtected
equals: #private.
assert: testSubjects ASubClass new AInnerClass new outerPrivateOverriddenByProtected
equals: #private.
)
public testOuterPrivateOverriddenByPublic = (
assert: testSubjects AClass new AInnerClass new outerPrivateOverriddenByPublic
equals: #private.
assert: testSubjects ASubClass new AInnerClass new outerPrivateOverriddenByPublic
equals: #private.
)
public testOuterProtectedOverriddenByPrivate = (
assert: testSubjects AClass new AInnerClass new outerProtectedOverriddenByPrivate
equals: #protected.
assert: testSubjects ASubClass new AInnerClass new outerProtectedOverriddenByPrivate
equals: #protected.
)
public testOuterProtectedOverriddenByPublic = (
assert: testSubjects AClass new AInnerClass new outerProtectedOverriddenByPublic
equals: #protected.
assert: testSubjects ASubClass new AInnerClass new outerProtectedOverriddenByPublic
equals: #public.
)
public testOuterPublicOverriddenByPrivate = (
assert: testSubjects AClass new AInnerClass new outerPublicOverriddenByPrivate
equals: #public.
assert: testSubjects ASubClass new AInnerClass new outerPublicOverriddenByPrivate
equals: #public.
)
public testOuterPublicOverriddenByProtected = (
assert: testSubjects AClass new AInnerClass new outerPublicOverriddenByProtected
equals: #public.
assert: testSubjects ASubClass new AInnerClass new outerPublicOverriddenByProtected
equals: #protected.
)
public testOverriddenMethodInASubInnerClassClassViaImplicitReceiverSend = (
assert: testSubjects ASubClass new callOverriddenMethod = #privateOverriddenMethod.
)
public testOverriddenMethodInInnerClassPublicSend = (
assert: testSubjects ASubClass new overriddenMethod equals: #overriddenMethod
)
public testOverriddenMethodInSuperClassViaImplicitReceiverSend = (
assert: testSubjects AClass new AInnerClass new callHiddenMethod = #privateHiddenMethod.
)
public testOverriddenMethodInSuperClassViaPublicSend = (
should: [testSubjects AClass new AInnerClass new hiddenMethod] signal: MessageNotUnderstood.
)
public testPrivateDoesNotUnderstand = (
assert: testSubjects WithPrivateDNU new foo
equals: #privateDNU.
)
public testPrivateImplicitReceiverSend = (
(* send a message via implicitReceiverSend which goes to a private method *)
assert: testSubjects ASubClass new ASubInnerClass new privateImplicitReceiverSend = #privateImplicitReceiverTarget.
)
public testPrivateImplicitReceiverSendWithInheritance = (
(* send a message via implicitReceiverSend which goes to a private method via inheritance *)
should: [testSubjects ASubClass new privateImplicitReceiverSendWithInheritance] signal: MessageNotUnderstood.
)
public testPrivateOuterSend = (
(* send a message via outerSend which goes to a private method *)
assert: testSubjects AClass new AInnerClass new outerPrivateMethod = #privateMethod.
)
public testPrivateOuterSendWithInheritance = (
(* send a message via outerSend which goes to a private method via inheritance *)
should: [testSubjects ASubClass new ASubInnerClass new privateOuterSendWithInheritance] signal: MessageNotUnderstood.
)
public testPrivatePublicSend = (
(* send a message via publicSend which goes to a private method *)
should: [testSubjects AClass new privateMethod] signal: MessageNotUnderstood.
)
public testPrivatePublicSendWithInheritance = (
(* send a message via publicSend which goes to a private method in the super chain *)
should: [testSubjects ASubClass new privateMethod] signal: MessageNotUnderstood.
)
public testPrivateSelfSend = (
(* send a message via selfSend which goes to a private method*)
assert: testSubjects AClass new selfPrivateMethod = #privateMethod.
)
public testPrivateSelfSendwithInheritance = (
(* send a message via selfSend which goes to a private method in the super chain *)
should: [ testSubjects ASubClass new selfPrivateMethod ] signal: MessageNotUnderstood.
)
public testPrivateSuperSend = (
(* send a message via superSend which goes to a private method *)
should: [ testSubjects ASubClass new superPrivateMethod ] signal: MessageNotUnderstood.
)
public testProtectedImplicitReceiverSend = (
(* send a message via implicitReceiverSend which goes to a protected method *)
assert: testSubjects ASubClass new ASubInnerClass new protectedImplicitReceiverSend = #protectedImplicitReceiverTarget.
)
public testProtectedImplicitReceiverSendWithInheritance = (
(* send a message via implicitReceiverSend which goes to a protected method via inheritance *)
assert: testSubjects ASubClass new protectedImplicitReceiverSendWithInheritance = #protectedMethod.
)
public testProtectedOuterSend = (
(* send a message via outerSend which goes to a protected method *)
assert: testSubjects AClass new AInnerClass new outerProtectedMethod = #protectedMethod.
)
public testProtectedOuterSendWithInheritance = (
(* send a message via outerSend which goes to a protected method via inheritance *)
assert: testSubjects ASubClass new ASubInnerClass new protectedOuterSendWithInheritance = #protectedMethod.
)
public testProtectedPublicSend = (
(* send a message via publicSend which goes to a protected method *)
should: [testSubjects AClass new protectedMethod] signal: MessageNotUnderstood.
)
public testProtectedPublicSendWithInheritance = (
(* send a message via publicSend which goes to a protected method in the super chain *)
should: [testSubjects ASubClass new protectedMethod] signal: MessageNotUnderstood.
)
public testProtectedSelfSend = (
(* send a message via selfSend which goes to a protected method*)
assert: testSubjects AClass new selfProtectedMethod = #protectedMethod.
)
public testProtectedSelfSendWithInheritance = (
(* send a message via selfSend which goes to a protected method in the super chain *)
assert: testSubjects ASubClass new selfProtectedMethod = #protectedMethod.
)
public testProtectedSendDNULookupClass = (
assert: testSubjects ADNUSubClass new sendSelfFoo equals: 'ADNUSubClass foo'.
assert: testSubjects ADNUSubClass new sendSuperFoo equals: 'ADNUClass doesNotUnderstand: foo'.
assert: testSubjects ADNUSubClass new sendSelfBar equals: 'ADNUSubClass doesNotUnderstand: bar'.
assert: testSubjects ADNUSubClass new sendSuperBar equals: 'ADNUClass doesNotUnderstand: bar'.
)
public testProtectedSuperSend = (
(* send a message via superSend which goes to a protected method *)
assert: testSubjects ASubClass new superProtectedMethod = #protectedMethod.
)
public testPublicImplicitReceiverSend = (
(* send a message via implicitReceiverSend which goes to a public method *)
assert: testSubjects ASubClass new ASubInnerClass new publicImplicitReceiverSend = #publicImplicitReceiverTarget.
)
public testPublicImplicitReceiverSendWithInheritance = (
(* send a message via implicitReceiverSend which goes to a public method via inheritance *)
assert: testSubjects ASubClass new publicImplicitReceiverSendWithInheritance = #publicMethod.
)
public testPublicOuterSend = (
(* send a message via outerSend which goes to a public method *)
assert: testSubjects AClass new AInnerClass new outerPublicMethod = #publicMethod.
)
public testPublicOuterSendWithInheritance = (
(* send a message via outerSend which goes to a public method via inheritance *)
assert: testSubjects ASubClass new ASubInnerClass new publicOuterSendWithInheritance = #publicMethod.
)
public testPublicPublicSend = (
(* send a message via publicSend which goes to a public method *)
assert: testSubjects AClass new publicMethod = #publicMethod.
)
public testPublicPublicSendWithInheritance = (
(* send a message via publicSend which goes to a public method in the super chain *)
assert: testSubjects ASubClass new publicMethod = #publicMethod.
)
public testPublicSelfSend = (
(* send a message via selfSend which goes to a public method*)
assert: testSubjects AClass new selfPublicMethod = #publicMethod.
)
public testPublicSelfSendWithInheritance = (
(* send a message via selfSend which goes to a public method in the super chain *)
assert: testSubjects ASubClass new selfPublicMethod = #publicMethod.
)
public testPublicSuperSend = (
(* send a message via superSend which goes to a public method *)
assert: testSubjects ASubClass new superPublicMethod = #publicMethod.
)
public testSelfPrivateOverriddenByProtected = (
assert: testSubjects ASubClass new selfPrivateOverriddenByProtected
equals: #private.
assert: testSubjects ASubClass new selfFromSubPrivateOverriddenByProtected
equals: #protected.
)
public testSelfPrivateOverriddenByPublic = (
assert: testSubjects ASubClass new selfPrivateOverriddenByPublic
equals: #private.
assert: testSubjects ASubClass new selfFromSubPrivateOverriddenByPublic
equals: #public.
)
public testSelfProtectedOverriddenByPrivate = (
assert: testSubjects ASubClass new selfProtectedOverriddenByPrivate
equals: #protected.
assert: testSubjects ASubClass new selfFromSubProtectedOverriddenByPrivate
equals: #private.
)
public testSelfProtectedOverriddenByPublic = (
assert: testSubjects ASubClass new selfProtectedOverriddenByPublic
equals: #public.
assert: testSubjects ASubClass new selfFromSubProtectedOverriddenByPublic
equals: #public.
)
public testSelfPublicOverriddenByPrivate = (
assert: testSubjects ASubClass new selfPublicOverriddenByPrivate
equals: #public.
assert: testSubjects ASubClass new selfFromSubPublicOverriddenByPrivate
equals: #private.
)
public testSelfPublicOverriddenByProtected = (
assert: testSubjects ASubClass new selfPublicOverriddenByProtected
equals: #protected.
assert: testSubjects ASubClass new selfFromSubPublicOverriddenByProtected
equals: #protected.
)
public testSuperPrivateOverriddenByProtected = (
should: [testSubjects ASubClass new superFromSubPrivateOverriddenByProtected]
signal: MessageNotUnderstood.
)
public testSuperPrivateOverriddenByPublic = (
should: [testSubjects ASubClass new superFromSubPrivateOverriddenByPublic]
signal: MessageNotUnderstood.
)
public testSuperProtectedOverriddenByPrivate = (
assert: testSubjects ASubClass new superFromSubProtectedOverriddenByPrivate
equals: #protected.
)
public testSuperProtectedOverriddenByPublic = (
assert: testSubjects ASubClass new superFromSubProtectedOverriddenByPublic
equals: #protected.
)
public testSuperPublicOverriddenByPrivate = (
assert: testSubjects ASubClass new superFromSubPublicOverriddenByPrivate
equals: #public.
)
public testSuperPublicOverriddenByProtected = (
assert: testSubjects ASubClass new superFromSubPublicOverriddenByProtected
equals: #public.
)
) : (
TEST_CONTEXT = ()
)
public class SlotAccessingTests = TestContext (
(* Try to access slots with different access modifiers, but only via public send.
Slot access is implemented via accessor methods - so fetching a slot falls back to finding the appropriate method.
All kind of different method sends are already tested in the MethodAcessingTests. *)
|
testSubjects = TestSubjects new.
|) (
public testDefaultSlotAccess = (
should: [testSubjects AClass new defaultSlot] signal: MessageNotUnderstood.
)
public testPrivateSlotAccess = (
should: [testSubjects AClass new privateSlot] signal: MessageNotUnderstood.
)
public testProtectedSlotAccess = (
should: [testSubjects AClass new protectedSlot] signal: MessageNotUnderstood.
)
public testPublicSlotAccess = (
assert: testSubjects AClass new publicSlot = #publicSlot.
)
) : (
TEST_CONTEXT = ()
)
public class TestSubjects = (
(* Holds a bunch of classes which we test against *)
) (
public class AClass = (
(* A class with a default access modifier. Slots and methods of all sort to be tested against *)
|
public publicSlot = #publicSlot.
protected protectedSlot = #protectedSlot.
private privateSlot = #privateSlot.
defaultSlot = #defaultSlot.
|) (
public class AInnerClass = (
(* A class to test outerSends with different accessModifiers.*)
|
public publicSlot = #innerPublicSlot.
protected protectedSlot = #innerProtectedSlot.
private privateSlot = #innerPrivateSlot.
defaultSlot = #innerDefaultSlot.
|) (
public callHiddenMethod = (
^hiddenMethod
)
defaultMethod = (
^#innerDefaultMethod
)
private hiddenMethod = (
(* This is a private method which hides a method with the same signature from an outer class.
The outer method should never be executed when called from an instance of this class via implicit receiver send. *)
^#privateHiddenMethod
)
public implicitPrivateOverriddenByProtected = (
^privateOverriddenByProtected
)
public implicitPrivateOverriddenByPublic = (
^privateOverriddenByPublic
)
public implicitProtectedOverriddenByPrivate = (
^protectedOverriddenByPrivate
)
public implicitProtectedOverriddenByPublic = (
^protectedOverriddenByPublic
)
public implicitPublicOverriddenByPrivate = (
^publicOverriddenByPrivate
)
public implicitPublicOverriddenByProtected = (
^publicOverriddenByProtected
)
public outerDefaultMethod = (
^outer AClass defaultMethod
)
public outerPrivateMethod = (
^outer AClass privateMethod
)
public outerPrivateOverriddenByProtected = (
^outer AClass privateOverriddenByProtected
)
public outerPrivateOverriddenByPublic = (
^outer AClass privateOverriddenByPublic
)
public outerProtectedMethod = (
^outer AClass protectedMethod
)
public outerProtectedOverriddenByPrivate = (
^outer AClass protectedOverriddenByPrivate
)
public outerProtectedOverriddenByPublic = (
^outer AClass protectedOverriddenByPublic
)
public outerPublicMethod = (
^outer AClass publicMethod
)
public outerPublicOverriddenByPrivate = (
^outer AClass publicOverriddenByPrivate
)
public outerPublicOverriddenByProtected = (
^outer AClass publicOverriddenByProtected
)
private privateMethod = (
^#innerPrivateMethod
)
protected protectedMethod = (
^#innerProtectedMethod
)
public publicMethod = (
^#innerPublicMethod
)
) : (
)
public callPrivateMethodOn: other = (
^other privateMethod
)
public callProtectedMethodOn: other = (
^other protectedMethod
)
defaultMethod = (
^#defaultMethod
)
public hiddenMethod = (
(* This is a public method which is hidden by an inner class.
This should never be executed when called from the inner class via implicit receiver send. *)
^#hiddenMethod
)
public overriddenMethod = (
(* This is a public method which is overridden by a subclass.
This should never be executed when called from the subclass via implicit receiver send. *)
^#overriddenMethod
)
private privateMethod = (
^#privateMethod
)
private privateOverriddenByProtected = (
^#private
)
private privateOverriddenByPublic = (
^#private
)
protected protectedMethod = (
^#protectedMethod
)
protected protectedOverriddenByPrivate = (
^#protected
)
protected protectedOverriddenByPublic = (
^#protected
)
public publicMethod = (
^#publicMethod
)
public publicOverriddenByPrivate = (
^#public
)
public publicOverriddenByProtected = (
^#public
)
public selfDefaultMethod = (
^self defaultMethod
)
public selfPrivateMethod = (
^self privateMethod
)
public selfPrivateOverriddenByProtected = (
^self privateOverriddenByProtected
)
public selfPrivateOverriddenByPublic = (
^self privateOverriddenByPublic
)
public selfProtectedMethod = (
^self protectedMethod
)
public selfProtectedOverriddenByPrivate = (
^self protectedOverriddenByPrivate
)
public selfProtectedOverriddenByPublic = (
^self protectedOverriddenByPublic
)
public selfPublicMethod = (
^self publicMethod
)
public selfPublicOverriddenByPrivate = (
^self publicOverriddenByPrivate
)
public selfPublicOverriddenByProtected = (
^self publicOverriddenByProtected
)
) : (
)
class ADNUClass = (
) (
protected doesNotUnderstand: message = (
^'ADNUClass doesNotUnderstand: ' , message selector
)
) : (
)
public class ADNUSubClass = ADNUClass (
) (
protected doesNotUnderstand: message = (
^'ADNUSubClass doesNotUnderstand: ' , message selector
)
foo = (
^'ADNUSubClass foo'
)
public sendSelfBar = (
^self bar
)
public sendSelfFoo = (
^self foo
)
public sendSuperBar = (
^super bar
)
public sendSuperFoo = (
^super foo
)
) : (
)
private class APrivateClass = () (
) : (
)
class AProtectedClass = () (
) : (
)
public class APublicClass = () (
public ping = (
^#pong
)
) : (
)
public class ASubClass = AClass (
(* A class to test access to inherited slots/methods *)
) (
public class ASubInnerClass = (
(* A Class to test outerSends in combination with inheritance *)
|
defaultImplicitReceiverTarget = #defaultImplicitReceiverTarget.
public publicImplicitReceiverTarget = #publicImplicitReceiverTarget.
protected protectedImplicitReceiverTarget = #protectedImplicitReceiverTarget.
private privateImplicitReceiverTarget = #privateImplicitReceiverTarget.
|) (
public defaultImplicitReceiverSend = (
^defaultImplicitReceiverTarget
)
public defaultOuterSendWithInheritance = (
^outer ASubClass defaultMethod
)
public privateImplicitReceiverSend = (
^privateImplicitReceiverTarget
)
public privateOuterSendWithInheritance = (
^outer ASubClass privateMethod
)
public protectedImplicitReceiverSend = (
^protectedImplicitReceiverTarget
)
public protectedOuterSendWithInheritance = (
^outer ASubClass protectedMethod
)
public publicImplicitReceiverSend = (
^publicImplicitReceiverTarget
)
public publicOuterSendWithInheritance = (
^outer ASubClass publicMethod
)
) : (
)
public callOverriddenMethod = (
^overriddenMethod
)
public defaultImplicitReceiverSendWithInheritance = (
^defaultMethod
)
private overriddenMethod = (
(* This is a private method which overrides a method with the same signature from a super class.
The super method should never be executed when called from an instance of this class via implicit receiver send. *)
^#privateOverriddenMethod
)
public privateImplicitReceiverSendWithInheritance = (
^privateMethod
)
protected privateOverriddenByProtected = (
^#protected
)
public privateOverriddenByPublic = (
^#public
)
public protectedImplicitReceiverSendWithInheritance = (
^protectedMethod
)
private protectedOverriddenByPrivate = (
^#private
)
public protectedOverriddenByPublic = (
^#public
)
public publicImplicitReceiverSendWithInheritance = (
^publicMethod
)
private publicOverriddenByPrivate = (
^#private
)
protected publicOverriddenByProtected = (
^#protected
)
public selfDefaultMethod = (
^self defaultMethod
)
public selfFromSubPrivateOverriddenByProtected = (
^self privateOverriddenByProtected
)
public selfFromSubPrivateOverriddenByPublic = (
^self privateOverriddenByPublic
)
public selfFromSubProtectedOverriddenByPrivate = (
^self protectedOverriddenByPrivate
)
public selfFromSubProtectedOverriddenByPublic = (
^self protectedOverriddenByPublic
)
public selfFromSubPublicOverriddenByPrivate = (
^self publicOverriddenByPrivate
)
public selfFromSubPublicOverriddenByProtected = (
^self publicOverriddenByProtected
)
public selfPrivateMethod = (
^self privateMethod
)
public selfProtectedMethod = (
^self protectedMethod
)
public selfPublicMethod = (
^self publicMethod
)
public superDefaultMethod = (
^super defaultMethod
)
public superFromSubPrivateOverriddenByProtected = (
^super privateOverriddenByProtected
)
public superFromSubPrivateOverriddenByPublic = (
^super privateOverriddenByPublic
)
public superFromSubProtectedOverriddenByPrivate = (
^super protectedOverriddenByPrivate
)
public superFromSubProtectedOverriddenByPublic = (
^super protectedOverriddenByPublic
)
public superFromSubPublicOverriddenByPrivate = (
^super publicOverriddenByPrivate
)
public superFromSubPublicOverriddenByProtected = (
^super publicOverriddenByProtected
)
public superPrivateMethod = (
^super privateMethod
)
public superProtectedMethod = (
^super protectedMethod
)
public superPublicMethod = (
^super publicMethod
)
) : (
)
public class WithPrivateDNU = () (
private doesNotUnderstand: message = (
^#privateDNU
)
) : (
)
) : (
)
) : (
)