Skip to content

Commit

Permalink
- Fixing names of test classes
Browse files Browse the repository at this point in the history
- Fixing problem when sharing the same talent and different original class
- Adding test
  • Loading branch information
tesonep committed Apr 15, 2021
1 parent 7668f9b commit f93a558
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 40 deletions.
11 changes: 10 additions & 1 deletion src/Talents-Tests/TaAbstractTalentTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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:#().
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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}).
Expand All @@ -20,7 +20,7 @@ TaChangingTalentTests >> testAddingMethodInADeepAliasTalent [
]

{ #category : #'tests-talents' }
TaChangingTalentTests >> testAddingMethodInATalent [
TaChangingTalentTest >> testAddingMethodInATalent [
| x |
x := Object new.
x addTalent: taTestTalent.
Expand All @@ -35,7 +35,7 @@ TaChangingTalentTests >> testAddingMethodInATalent [
]

{ #category : #'tests-talents' }
TaChangingTalentTests >> testChangingAMethodInATalent [
TaChangingTalentTest >> testChangingAMethodInATalent [
| x |
x := Object new.
x addTalent: taTestTalent.
Expand All @@ -50,7 +50,7 @@ TaChangingTalentTests >> testChangingAMethodInATalent [
]

{ #category : #'tests-traits' }
TaChangingTalentTests >> testChangingAMethodInATrait [
TaChangingTalentTest >> testChangingAMethodInATrait [
| x traitedClass |
traitedClass := Object copyWithTrait: taTestTalent.
x := traitedClass new.
Expand All @@ -65,7 +65,7 @@ TaChangingTalentTests >> testChangingAMethodInATrait [
]

{ #category : #'tests-talents' }
TaChangingTalentTests >> testChangingMethodInADeepAliasTalent [
TaChangingTalentTest >> testChangingMethodInADeepAliasTalent [
| x |
x := Object new.
x addTalent: (taTestTalent asTraitComposition @= {#newMessage -> #someMessage}).
Expand All @@ -80,7 +80,7 @@ TaChangingTalentTests >> testChangingMethodInADeepAliasTalent [
]

{ #category : #'tests-talents' }
TaChangingTalentTests >> testRemovingAMethodInATalent [
TaChangingTalentTest >> testRemovingAMethodInATalent [
| x |
x := Object new.
x addTalent: taTestTalent.
Expand All @@ -93,7 +93,7 @@ TaChangingTalentTests >> testRemovingAMethodInATalent [
]

{ #category : #'tests-talents' }
TaChangingTalentTests >> testRemovingMethodInADeepAliasTalent [
TaChangingTalentTest >> testRemovingMethodInADeepAliasTalent [
| x |
x := Object new.
x addTalent: (taTestTalent asTraitComposition @= {#newMessage -> #someMessage}).
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,7 +16,7 @@ TaCopyingObjectsTests >> testCopyingArray [
]

{ #category : #tests }
TaCopyingObjectsTests >> testCopyingBag [
TaCopyingObjectsTest >> testCopyingBag [
| x t1 x2 |
x := { 1. 2. 3. } asBag.
t1 := self newTalent: #Tamanio.
Expand All @@ -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.
Expand All @@ -51,7 +51,7 @@ TaCopyingObjectsTests >> testRemovingInACopy [
]

{ #category : #tests }
TaCopyingObjectsTests >> testReplacingBag [
TaCopyingObjectsTest >> testReplacingBag [
| x t1 x2 |
x := { 1. 2. 3. } asBag.
t1 := self newTalent: #Tamanio.
Expand All @@ -68,7 +68,7 @@ TaCopyingObjectsTests >> testReplacingBag [
]

{ #category : #tests }
TaCopyingObjectsTests >> testTalentedCopy [
TaCopyingObjectsTest >> testTalentedCopy [
| t1 x x2 |
t1 := self newTalent: #SomeTalent.
t1 compile: 'aMessage
Expand Down
50 changes: 50 additions & 0 deletions src/Talents-Tests/TaSharingAnonymousClassesTest.class.st
Original file line number Diff line number Diff line change
@@ -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



]
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,7 +35,7 @@ TaSimpleTalentTests >> testAdding2SimpleTalent [
]

{ #category : #'tests-traits' }
TaSimpleTalentTests >> testAdding2SimpleTrait [
TaSimpleTalentTest >> testAdding2SimpleTrait [
| x t2 traitedClass |
traitedClass := Object copyWithTrait: taTestTalent.
x := traitedClass new.
Expand Down Expand Up @@ -65,7 +65,7 @@ TaSimpleTalentTests >> testAdding2SimpleTrait [
]

{ #category : #'tests-talents' }
TaSimpleTalentTests >> testAddingSimpleTalent [
TaSimpleTalentTest >> testAddingSimpleTalent [
| x |
x := Object new.
x addTalent: taTestTalent.
Expand All @@ -75,7 +75,7 @@ TaSimpleTalentTests >> testAddingSimpleTalent [
]

{ #category : #'tests-traits' }
TaSimpleTalentTests >> testAddingSimpleTrait [
TaSimpleTalentTest >> testAddingSimpleTrait [
| x traitedClass |
traitedClass := Object copyWithTrait: taTestTalent.
x := traitedClass new.
Expand All @@ -85,7 +85,7 @@ TaSimpleTalentTests >> testAddingSimpleTrait [
]

{ #category : #'tests-talents' }
TaSimpleTalentTests >> testClassSideMethods [
TaSimpleTalentTest >> testClassSideMethods [
| x |
x := TaTestClassWithInstanceVariable new.
x anInstanceVariable: 23.
Expand All @@ -97,7 +97,7 @@ TaSimpleTalentTests >> testClassSideMethods [
]

{ #category : #'tests-talents' }
TaSimpleTalentTests >> testCopyingObjectState [
TaSimpleTalentTest >> testCopyingObjectState [
| x |
x := TaTestClassWithInstanceVariable new.
x anInstanceVariable: 23.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,7 +21,7 @@ TaTalentCompositionTests >> testAddingTwoNonClashingTalents [
]

{ #category : #tests }
TaTalentCompositionTests >> testAliasMethod [
TaTalentCompositionTest >> testAliasMethod [
| x |
x := Object new.
x addTalent: (taTestTalent asTraitComposition @ { #otherName -> #someMessage}).
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -56,7 +56,7 @@ TaTalentCompositionTests >> testDeepAliasRecursiveMethod [
]

{ #category : #tests }
TaTalentCompositionTests >> testRemovingMethod [
TaTalentCompositionTest >> testRemovingMethod [
| x |
x := Object new.
x addTalent: (taTestTalentWithTwoMethods asTraitComposition - {#aM2} ).
Expand All @@ -67,7 +67,7 @@ TaTalentCompositionTests >> testRemovingMethod [
]

{ #category : #tests }
TaTalentCompositionTests >> testValidateDuplicateMethod [
TaTalentCompositionTest >> testValidateDuplicateMethod [
| x t1 t2|

x := Object new.
Expand All @@ -82,7 +82,7 @@ TaTalentCompositionTests >> testValidateDuplicateMethod [
]

{ #category : #tests }
TaTalentCompositionTests >> testValidateDuplicateSlot [
TaTalentCompositionTest >> testValidateDuplicateSlot [
| x t1 t2|

x := Object new.
Expand All @@ -95,7 +95,7 @@ TaTalentCompositionTests >> testValidateDuplicateSlot [
]

{ #category : #tests }
TaTalentCompositionTests >> testValidateDuplicationOfTalent [
TaTalentCompositionTest >> testValidateDuplicationOfTalent [
| x |
x := Object new.
self should:[x addTalent: taTestTalent , taTestTalent] raise:Error.
Expand Down
7 changes: 7 additions & 0 deletions src/Talents/TaAbstractComposition.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #TaAbstractComposition }

{ #category : #'*Talents' }
TaAbstractComposition >> >> anAssociation [

^ self @@ { anAssociation }
]
6 changes: 4 additions & 2 deletions src/Talents/TalentInstaller.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
#classInstVars : [
'uniqueInstance'
],
#category : 'Talents-Installer'
#category : #'Talents-Installer'
}

{ #category : #'as yet unclassified' }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f93a558

Please sign in to comment.