From f93a558da6b8521264f2d6387feb84786b5d86d2 Mon Sep 17 00:00:00 2001 From: Pablo Tesone Date: Thu, 15 Apr 2021 12:03:05 +0200 Subject: [PATCH] - Fixing names of test classes - Fixing problem when sharing the same talent and different original class - Adding test --- .../TaAbstractTalentTest.class.st | 11 +++- ...rayTests.class.st => TaArrayTest.class.st} | 6 +-- ...class.st => TaChangingTalentTest.class.st} | 18 +++---- ...class.st => TaCopyingObjectsTest.class.st} | 14 +++--- .../TaSharingAnonymousClassesTest.class.st | 50 +++++++++++++++++++ ...s.class.st => TaSimpleTalentTest.class.st} | 16 +++--- ...ss.st => TaTalentCompositionTest.class.st} | 20 ++++---- .../TaAbstractComposition.extension.st | 7 +++ src/Talents/TalentInstaller.class.st | 6 ++- 9 files changed, 108 insertions(+), 40 deletions(-) rename src/Talents-Tests/{TaArrayTests.class.st => TaArrayTest.class.st} (75%) rename src/Talents-Tests/{TaChangingTalentTests.class.st => TaChangingTalentTest.class.st} (79%) rename src/Talents-Tests/{TaCopyingObjectsTests.class.st => TaCopyingObjectsTest.class.st} (83%) create mode 100644 src/Talents-Tests/TaSharingAnonymousClassesTest.class.st rename src/Talents-Tests/{TaSimpleTalentTests.class.st => TaSimpleTalentTest.class.st} (86%) rename src/Talents-Tests/{TaTalentCompositionTests.class.st => TaTalentCompositionTest.class.st} (81%) create mode 100644 src/Talents/TaAbstractComposition.extension.st diff --git a/src/Talents-Tests/TaAbstractTalentTest.class.st b/src/Talents-Tests/TaAbstractTalentTest.class.st index 7d2b377..e7f2e3d 100644 --- a/src/Talents-Tests/TaAbstractTalentTest.class.st +++ b/src/Talents-Tests/TaAbstractTalentTest.class.st @@ -15,6 +15,15 @@ Class { #category : #'Talents-Tests' } +{ #category : #'instance creation' } +TaAbstractTalentTest >> newClass: aName with: slots [ + | class | + class := Object subclass: aName slots: slots classVariables: #() package: 'Talents-Tests-TestClasses'. + createdClasses add:class. + + ^class. +] + { #category : #'as yet unclassified' } TaAbstractTalentTest >> newTalent: aName [ ^ self newTalent:aName with:#(). @@ -23,7 +32,7 @@ TaAbstractTalentTest >> newTalent: aName [ { #category : #'instance creation' } TaAbstractTalentTest >> newTalent: aName with: slots [ | class | - class := Trait named: aName uses: { } slots: slots category: 'Talents-Tests-TestClasses' env: self class environment. + class := Trait named: aName uses: { } slots: slots package: 'Talents-Tests-TestClasses' env: self class environment. createdClasses add:class. ^class. diff --git a/src/Talents-Tests/TaArrayTests.class.st b/src/Talents-Tests/TaArrayTest.class.st similarity index 75% rename from src/Talents-Tests/TaArrayTests.class.st rename to src/Talents-Tests/TaArrayTest.class.st index 26a139f..4a4e31d 100644 --- a/src/Talents-Tests/TaArrayTests.class.st +++ b/src/Talents-Tests/TaArrayTest.class.st @@ -1,11 +1,11 @@ Class { - #name : #TaArrayTests, + #name : #TaArrayTest, #superclass : #TaAbstractTalentTest, - #category : 'Talents-Tests' + #category : #'Talents-Tests' } { #category : #tests } -TaArrayTests >> testInitializeSlot [ +TaArrayTest >> testInitializeSlot [ | x | x := {1. 2. 3}. x addTalent: taTalentWithASlotInitialized. diff --git a/src/Talents-Tests/TaChangingTalentTests.class.st b/src/Talents-Tests/TaChangingTalentTest.class.st similarity index 79% rename from src/Talents-Tests/TaChangingTalentTests.class.st rename to src/Talents-Tests/TaChangingTalentTest.class.st index 8a7cfc5..530fb9b 100644 --- a/src/Talents-Tests/TaChangingTalentTests.class.st +++ b/src/Talents-Tests/TaChangingTalentTest.class.st @@ -1,11 +1,11 @@ Class { - #name : #TaChangingTalentTests, + #name : #TaChangingTalentTest, #superclass : #TaAbstractTalentTest, - #category : 'Talents-Tests' + #category : #'Talents-Tests' } { #category : #'tests-talents' } -TaChangingTalentTests >> testAddingMethodInADeepAliasTalent [ +TaChangingTalentTest >> testAddingMethodInADeepAliasTalent [ | x | x := Object new. x addTalent: (taTestTalent asTraitComposition @= {#newMessage -> #someMessage}). @@ -20,7 +20,7 @@ TaChangingTalentTests >> testAddingMethodInADeepAliasTalent [ ] { #category : #'tests-talents' } -TaChangingTalentTests >> testAddingMethodInATalent [ +TaChangingTalentTest >> testAddingMethodInATalent [ | x | x := Object new. x addTalent: taTestTalent. @@ -35,7 +35,7 @@ TaChangingTalentTests >> testAddingMethodInATalent [ ] { #category : #'tests-talents' } -TaChangingTalentTests >> testChangingAMethodInATalent [ +TaChangingTalentTest >> testChangingAMethodInATalent [ | x | x := Object new. x addTalent: taTestTalent. @@ -50,7 +50,7 @@ TaChangingTalentTests >> testChangingAMethodInATalent [ ] { #category : #'tests-traits' } -TaChangingTalentTests >> testChangingAMethodInATrait [ +TaChangingTalentTest >> testChangingAMethodInATrait [ | x traitedClass | traitedClass := Object copyWithTrait: taTestTalent. x := traitedClass new. @@ -65,7 +65,7 @@ TaChangingTalentTests >> testChangingAMethodInATrait [ ] { #category : #'tests-talents' } -TaChangingTalentTests >> testChangingMethodInADeepAliasTalent [ +TaChangingTalentTest >> testChangingMethodInADeepAliasTalent [ | x | x := Object new. x addTalent: (taTestTalent asTraitComposition @= {#newMessage -> #someMessage}). @@ -80,7 +80,7 @@ TaChangingTalentTests >> testChangingMethodInADeepAliasTalent [ ] { #category : #'tests-talents' } -TaChangingTalentTests >> testRemovingAMethodInATalent [ +TaChangingTalentTest >> testRemovingAMethodInATalent [ | x | x := Object new. x addTalent: taTestTalent. @@ -93,7 +93,7 @@ TaChangingTalentTests >> testRemovingAMethodInATalent [ ] { #category : #'tests-talents' } -TaChangingTalentTests >> testRemovingMethodInADeepAliasTalent [ +TaChangingTalentTest >> testRemovingMethodInADeepAliasTalent [ | x | x := Object new. x addTalent: (taTestTalent asTraitComposition @= {#newMessage -> #someMessage}). diff --git a/src/Talents-Tests/TaCopyingObjectsTests.class.st b/src/Talents-Tests/TaCopyingObjectsTest.class.st similarity index 83% rename from src/Talents-Tests/TaCopyingObjectsTests.class.st rename to src/Talents-Tests/TaCopyingObjectsTest.class.st index dee9b64..bf10bc5 100644 --- a/src/Talents-Tests/TaCopyingObjectsTests.class.st +++ b/src/Talents-Tests/TaCopyingObjectsTest.class.st @@ -1,11 +1,11 @@ Class { - #name : #TaCopyingObjectsTests, + #name : #TaCopyingObjectsTest, #superclass : #TaAbstractTalentTest, - #category : 'Talents-Tests' + #category : #'Talents-Tests' } { #category : #tests } -TaCopyingObjectsTests >> testCopyingArray [ +TaCopyingObjectsTest >> testCopyingArray [ | x t1 | x := { 1. 2. 3. }. t1 := self newTalent: #Tamanio. @@ -16,7 +16,7 @@ TaCopyingObjectsTests >> testCopyingArray [ ] { #category : #tests } -TaCopyingObjectsTests >> testCopyingBag [ +TaCopyingObjectsTest >> testCopyingBag [ | x t1 x2 | x := { 1. 2. 3. } asBag. t1 := self newTalent: #Tamanio. @@ -33,7 +33,7 @@ TaCopyingObjectsTests >> testCopyingBag [ ] { #category : #tests } -TaCopyingObjectsTests >> testRemovingInACopy [ +TaCopyingObjectsTest >> testRemovingInACopy [ | x t1 x2 x3 | x := { 1. 2. 3. } asBag. t1 := self newTalent: #Tamanio. @@ -51,7 +51,7 @@ TaCopyingObjectsTests >> testRemovingInACopy [ ] { #category : #tests } -TaCopyingObjectsTests >> testReplacingBag [ +TaCopyingObjectsTest >> testReplacingBag [ | x t1 x2 | x := { 1. 2. 3. } asBag. t1 := self newTalent: #Tamanio. @@ -68,7 +68,7 @@ TaCopyingObjectsTests >> testReplacingBag [ ] { #category : #tests } -TaCopyingObjectsTests >> testTalentedCopy [ +TaCopyingObjectsTest >> testTalentedCopy [ | t1 x x2 | t1 := self newTalent: #SomeTalent. t1 compile: 'aMessage diff --git a/src/Talents-Tests/TaSharingAnonymousClassesTest.class.st b/src/Talents-Tests/TaSharingAnonymousClassesTest.class.st new file mode 100644 index 0000000..0e51537 --- /dev/null +++ b/src/Talents-Tests/TaSharingAnonymousClassesTest.class.st @@ -0,0 +1,50 @@ +Class { + #name : #TaSharingAnonymousClassesTest, + #superclass : #TaAbstractTalentTest, + #instVars : [ + 'objectA', + 'objectB', + 'aTalent', + 'aClass', + 'anotherClass', + 'objectC' + ], + #category : #'Talents-Tests' +} + +{ #category : #tests } +TaSharingAnonymousClassesTest >> setUp [ + + super setUp. + + aTalent := self newTalent: #ATalent with: #(). + aClass := self newClass: #ATClass1 with: #(). + anotherClass := self newClass: #ATClass2 with: #(). + + objectA := aClass new . + objectB := anotherClass new . + objectC := aClass new . + + objectA addTalent: aTalent. + objectB addTalent: aTalent. + objectC addTalent: aTalent. + +] + +{ #category : #tests } +TaSharingAnonymousClassesTest >> testHavingTwoObjectsWithTheSameTalentAndDifferentInitialClassDoNotSharesAnonymousClass [ + + self deny: objectA class == objectB class + + + +] + +{ #category : #tests } +TaSharingAnonymousClassesTest >> testHavingTwoObjectsWithTheSameTalentAndInitialClassSharesAnonymousClass [ + + self assert: objectA class == objectC class + + + +] diff --git a/src/Talents-Tests/TaSimpleTalentTests.class.st b/src/Talents-Tests/TaSimpleTalentTest.class.st similarity index 86% rename from src/Talents-Tests/TaSimpleTalentTests.class.st rename to src/Talents-Tests/TaSimpleTalentTest.class.st index db689ac..0c1a44d 100644 --- a/src/Talents-Tests/TaSimpleTalentTests.class.st +++ b/src/Talents-Tests/TaSimpleTalentTest.class.st @@ -1,11 +1,11 @@ Class { - #name : #TaSimpleTalentTests, + #name : #TaSimpleTalentTest, #superclass : #TaAbstractTalentTest, - #category : 'Talents-Tests' + #category : #'Talents-Tests' } { #category : #'tests-talents' } -TaSimpleTalentTests >> testAdding2SimpleTalent [ +TaSimpleTalentTest >> testAdding2SimpleTalent [ | x t2 | x := Object new. x addTalent: taTestTalent. @@ -35,7 +35,7 @@ TaSimpleTalentTests >> testAdding2SimpleTalent [ ] { #category : #'tests-traits' } -TaSimpleTalentTests >> testAdding2SimpleTrait [ +TaSimpleTalentTest >> testAdding2SimpleTrait [ | x t2 traitedClass | traitedClass := Object copyWithTrait: taTestTalent. x := traitedClass new. @@ -65,7 +65,7 @@ TaSimpleTalentTests >> testAdding2SimpleTrait [ ] { #category : #'tests-talents' } -TaSimpleTalentTests >> testAddingSimpleTalent [ +TaSimpleTalentTest >> testAddingSimpleTalent [ | x | x := Object new. x addTalent: taTestTalent. @@ -75,7 +75,7 @@ TaSimpleTalentTests >> testAddingSimpleTalent [ ] { #category : #'tests-traits' } -TaSimpleTalentTests >> testAddingSimpleTrait [ +TaSimpleTalentTest >> testAddingSimpleTrait [ | x traitedClass | traitedClass := Object copyWithTrait: taTestTalent. x := traitedClass new. @@ -85,7 +85,7 @@ TaSimpleTalentTests >> testAddingSimpleTrait [ ] { #category : #'tests-talents' } -TaSimpleTalentTests >> testClassSideMethods [ +TaSimpleTalentTest >> testClassSideMethods [ | x | x := TaTestClassWithInstanceVariable new. x anInstanceVariable: 23. @@ -97,7 +97,7 @@ TaSimpleTalentTests >> testClassSideMethods [ ] { #category : #'tests-talents' } -TaSimpleTalentTests >> testCopyingObjectState [ +TaSimpleTalentTest >> testCopyingObjectState [ | x | x := TaTestClassWithInstanceVariable new. x anInstanceVariable: 23. diff --git a/src/Talents-Tests/TaTalentCompositionTests.class.st b/src/Talents-Tests/TaTalentCompositionTest.class.st similarity index 81% rename from src/Talents-Tests/TaTalentCompositionTests.class.st rename to src/Talents-Tests/TaTalentCompositionTest.class.st index c056865..1f5a65d 100644 --- a/src/Talents-Tests/TaTalentCompositionTests.class.st +++ b/src/Talents-Tests/TaTalentCompositionTest.class.st @@ -1,11 +1,11 @@ Class { - #name : #TaTalentCompositionTests, + #name : #TaTalentCompositionTest, #superclass : #TaAbstractTalentTest, - #category : 'Talents-Tests' + #category : #'Talents-Tests' } { #category : #tests } -TaTalentCompositionTests >> testAddingTwoNonClashingTalents [ +TaTalentCompositionTest >> testAddingTwoNonClashingTalents [ | x | x := TaTestClassWithInstanceVariable new. x anInstanceVariable: 32. @@ -21,7 +21,7 @@ TaTalentCompositionTests >> testAddingTwoNonClashingTalents [ ] { #category : #tests } -TaTalentCompositionTests >> testAliasMethod [ +TaTalentCompositionTest >> testAliasMethod [ | x | x := Object new. x addTalent: (taTestTalent asTraitComposition @ { #otherName -> #someMessage}). @@ -32,7 +32,7 @@ TaTalentCompositionTests >> testAliasMethod [ ] { #category : #tests } -TaTalentCompositionTests >> testAliasRecursiveMethod [ +TaTalentCompositionTest >> testAliasRecursiveMethod [ " The alias is not rewriting the uses of this message inside the talent. A deep alias performs this" | x | x := Object new. @@ -44,7 +44,7 @@ TaTalentCompositionTests >> testAliasRecursiveMethod [ ] { #category : #tests } -TaTalentCompositionTests >> testDeepAliasRecursiveMethod [ +TaTalentCompositionTest >> testDeepAliasRecursiveMethod [ " The alias is not rewriting the uses of this message inside the talent. A deep alias performs this" | x | x := Object new. @@ -56,7 +56,7 @@ TaTalentCompositionTests >> testDeepAliasRecursiveMethod [ ] { #category : #tests } -TaTalentCompositionTests >> testRemovingMethod [ +TaTalentCompositionTest >> testRemovingMethod [ | x | x := Object new. x addTalent: (taTestTalentWithTwoMethods asTraitComposition - {#aM2} ). @@ -67,7 +67,7 @@ TaTalentCompositionTests >> testRemovingMethod [ ] { #category : #tests } -TaTalentCompositionTests >> testValidateDuplicateMethod [ +TaTalentCompositionTest >> testValidateDuplicateMethod [ | x t1 t2| x := Object new. @@ -82,7 +82,7 @@ TaTalentCompositionTests >> testValidateDuplicateMethod [ ] { #category : #tests } -TaTalentCompositionTests >> testValidateDuplicateSlot [ +TaTalentCompositionTest >> testValidateDuplicateSlot [ | x t1 t2| x := Object new. @@ -95,7 +95,7 @@ TaTalentCompositionTests >> testValidateDuplicateSlot [ ] { #category : #tests } -TaTalentCompositionTests >> testValidateDuplicationOfTalent [ +TaTalentCompositionTest >> testValidateDuplicationOfTalent [ | x | x := Object new. self should:[x addTalent: taTestTalent , taTestTalent] raise:Error. diff --git a/src/Talents/TaAbstractComposition.extension.st b/src/Talents/TaAbstractComposition.extension.st new file mode 100644 index 0000000..e511b63 --- /dev/null +++ b/src/Talents/TaAbstractComposition.extension.st @@ -0,0 +1,7 @@ +Extension { #name : #TaAbstractComposition } + +{ #category : #'*Talents' } +TaAbstractComposition >> >> anAssociation [ + + ^ self @@ { anAssociation } +] diff --git a/src/Talents/TalentInstaller.class.st b/src/Talents/TalentInstaller.class.st index 0ecd7b2..59d19ce 100644 --- a/src/Talents/TalentInstaller.class.st +++ b/src/Talents/TalentInstaller.class.st @@ -7,7 +7,7 @@ Class { #classInstVars : [ 'uniqueInstance' ], - #category : 'Talents-Installer' + #category : #'Talents-Installer' } { #category : #'as yet unclassified' } @@ -122,7 +122,9 @@ TalentInstaller >> doCopyObject: anObject withoutTalent: aClass [ { #category : #operations } TalentInstaller >> extendClass: aClass with: aTalent [ | newClass | - talentedClasses associations detect: [ :e | e value = aTalent ] ifFound: [ :e | ^ e key ] ifNone: [ ]. + talentedClasses associations + detect: [ :e | e key superclass = aClass and: [e value = aTalent] ] + ifFound: [ :e | ^ e key ] ifNone: [ ]. newClass := Smalltalk anonymousClassInstaller make: [ :builder | builder