Skip to content

Commit

Permalink
Merge pull request #39 from moosetechnology/alltaggedentities-improve…
Browse files Browse the repository at this point in the history
…-tests

Improve tests and `allTaggedEntities`
  • Loading branch information
Gabriel-Darbord authored Aug 31, 2024
2 parents 4eecf32 + 40451ce commit d8aeecb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ FamixTagImportAndExportManyObjectsTest >> testNumberOfClasses [
]

{ #category : #tests }
FamixTagImportAndExportManyObjectsTest >> testNumberOftags [
FamixTagImportAndExportManyObjectsTest >> testNumberOfTags [
self assert: model tags size equals: 1000
]
48 changes: 48 additions & 0 deletions src/Famix-Tagging-Tests/FamixTagMockModelBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Class {
#category : #'Famix-Tagging-Tests'
}

{ #category : #'model-building' }
FamixTagMockModelBuilder class >> buildComplexModel [

^ self new buildComplexModel
]

{ #category : #running }
FamixTagMockModelBuilder class >> buildModel [
^self new buildModel
Expand All @@ -32,6 +38,48 @@ FamixTagMockModelBuilder >> buildCodeTag [
tagInterval: (10 to: 300) forEntity: entity sourceAnchor: entity sourceAnchor
]

{ #category : #'model-building' }
FamixTagMockModelBuilder >> buildComplexModel [

| package fooClass factoryClass dataAttribute dataSetter makeFooMethod tag1 tag2 |
model := FamixTagTestModel new.

package := model newPackageNamed: 'Foo-Core'.
package types: {
(fooClass := model newClassNamed: 'Foo').
(factoryClass := model newClassNamed: 'FooFactory') }.

"Foo.data"
dataAttribute := model newAttributeNamed: 'data'.
dataAttribute parentType: fooClass.

"Foo >> #data:"
dataSetter := model newMethodNamed: 'data:'.
dataSetter parentType: fooClass.
dataSetter accesses: { (model newAccess variable: dataAttribute) }.

"FooFactory >> #makeFooWith:"
makeFooMethod := model newMethodNamed: 'makeFooWith:'.
makeFooMethod parentType: factoryClass.
makeFooMethod outgoingInvocations: {
(model newInvocation receiver: fooClass).
(model newInvocation candidates: { dataSetter }) }.

"create and set tags"
tag1 := model addTaggingEntityFirst: (FamixTag named: 'tag1').
tag1 tagEntity: package.
tag1 tagEntity: fooClass.
tag1 tagEntity: dataSetter incomingInvocations first.
tag1 tagEntity: dataAttribute.

tag2 := model addTaggingEntityFirst: (FamixTag named: 'tag2').
tag2 tagEntity: fooClass.
tag2 tagEntity: dataSetter accesses first.
tag2 tagEntity: makeFooMethod.

^ model
]

{ #category : #'model-building' }
FamixTagMockModelBuilder >> buildModel [
self simpleModel.
Expand Down
8 changes: 4 additions & 4 deletions src/Famix-Tagging-Tests/FamixTagMooseEntityTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Class {
}

{ #category : #tests }
FamixTagMooseEntityTest >> testHasTagg [
| class1 tagDB |
FamixTagMooseEntityTest >> testHasTag [
| class1 tagDB |
class1 := model allModelClasses detect: [ :c | c name = 'Class1' ].
tagDB := model tags detect: [ :t | t name = 'database' ].
self assert: (class1 hasTag: tagDB ).
]

{ #category : #tests }
FamixTagMooseEntityTest >> testHasTaggNamed [
| class1 |
FamixTagMooseEntityTest >> testHasTagNamed [
| class1 |
class1 := model allModelClasses detect: [ :c | c name = 'Class1' ].
self assert: (class1 hasTagNamed: 'database' ).
]
21 changes: 19 additions & 2 deletions src/Famix-Tagging-Tests/FamixTagMooseModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,25 @@ FamixTagMooseModelTest >> testAllTagAssociations [

{ #category : #tests }
FamixTagMooseModelTest >> testAllTaggedEntities [
self assert: (model allTaggedEntities size) equals: 1.
self assertCollection: (model allTaggedEntities ) hasSameElements: {model entityNamed: 'Package1::Class1'}

self
assertCollection: model allTaggedEntities
hasSameElements: { (model entityNamed: 'Package1::Class1') }.

"more complex model with multiple tags at different levels"
model := FamixTagMockModelBuilder buildComplexModel.

"on a model"
self
assertCollection: model allTaggedEntities
hasSameElements: (model select: [ :entity | entity isTagged ]).

"on an entity"
self
assertCollection: (model entityNamed: 'Foo') allTaggedEntities
hasSameElements: {
(model entityNamed: 'Foo').
(model entityNamed: 'data') }
]

{ #category : #tests }
Expand Down
7 changes: 3 additions & 4 deletions src/Famix-Tagging/MooseEntity.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ MooseEntity >> allTagAssociations: aCollection [

{ #category : #'*Famix-Tagging' }
MooseEntity >> allTaggedEntities [

| taggedEntities |

taggedEntities := OrderedCollection new.
self allTaggedEntitiesIn: taggedEntities .
^ taggedEntities .

self allTaggedEntitiesIn: taggedEntities.
^ taggedEntities
]

{ #category : #'*Famix-Tagging' }
Expand Down
3 changes: 1 addition & 2 deletions src/Famix-Tagging/MooseModel.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ MooseModel >> addTaggingEntityFirst: anElement [
{ #category : #'*Famix-Tagging' }
MooseModel >> allTaggedEntities [

^ self allTags flatCollectAsSet: [ :tag |
tag taggedEntitiesInModel: self ]
^ self allTagAssociations collect: [ :assoc | assoc entity ] as: Set
]

{ #category : #'*Famix-Tagging' }
Expand Down

0 comments on commit d8aeecb

Please sign in to comment.