Skip to content

Commit

Permalink
Add more tests and fix bug found with this
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jun 14, 2024
1 parent 17a9eaa commit 9534e6d
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Famix-Diff-Core-Tests/FamixDiffResultTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,46 @@ FamixDiffResultTest >> setUp [
result := (FXDiff runOnBaseModel: model1 targetModel: model2) result
]

{ #category : #tests }
FamixDiffResultTest >> testAdditions [

| additions |
additions := result additions.
self assert: additions size equals: 5.
additions do: [ :change | self assert: change isAddition ].
self assert: additions class equals: result class
]

{ #category : #tests }
FamixDiffResultTest >> testMoves [

| moves |
moves := result moves.
self assert: moves size equals: 0.
moves do: [ :change | self assert: change isMove ].
self assert: moves class equals: result class
]

{ #category : #tests }
FamixDiffResultTest >> testRemovals [

| removals |
removals := result removals.
self assert: removals size equals: 11.
removals do: [ :change | self assert: change isRemoval ].
self assert: removals class equals: result class
]

{ #category : #tests }
FamixDiffResultTest >> testRenames [

| moves |
moves := result renames.
self assert: moves size equals: 0.
moves do: [ :change | self assert: change isRename ].
self assert: moves class equals: result class
]

{ #category : #tests }
FamixDiffResultTest >> testWithoutStubs [

Expand Down
29 changes: 29 additions & 0 deletions src/Famix-Diff-Core-Tests/FamixDiffTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,32 @@ FamixDiffTest >> testMatched [
snapshot diffComputer changesDico at: entity put: FamixMoveChange new.
self assert: (snapshot diffComputer matched: entity)
]

{ #category : #tests }
FamixDiffTest >> testMovedEntities [

| moves |
self createTestDiffForAdditionsAndRemovalsEdgeCases.
moves := result moves.

self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStPackage ]).
self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStClass ]).
self assert: (moves select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 2.
self assertEmpty: (moves select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ])
]

{ #category : #tests }
FamixDiffTest >> testRemovedEntities [

| removals |
self createTestDiffForAdditionsAndRemovalsEdgeCases.
removals := result removals.

self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStPackage ]) size equals: 1.
self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStPackage ]) entity name equals: self packageName1.
self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStClass ]) size equals: 1.
self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStClass ]) entity name equals: #C1.
self assert: (removals select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 1.
self assert: (removals detect: [ :change | change baseEntity isKindOf: FamixStMethod ]) entity name equals: #m1.
self assertEmpty: (removals select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ])
]
33 changes: 32 additions & 1 deletion src/Famix-Diff-Core/FamixDiffResolver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ FamixDiffResolver >> hasParentMatched: entity [
^ true
]

{ #category : #testing }
FamixDiffResolver >> hasParentMatched: entity ignoringParentsIn: aCollection [

entity parentsDo: [ :parent | ((aCollection includes: parent) or: [ (self shouldMatch: parent) not or: [ self matched: parent ] ]) ifFalse: [ ^ false ] ].

^ true
]

{ #category : #'run-entities' }
FamixDiffResolver >> identityMatchesFrom: baseEntities to: targetEntities [
"Find the entities that are exactly the same between base version and target version (using #identityMatch:resolver: message).
Expand Down Expand Up @@ -234,7 +242,23 @@ FamixDiffResolver >> lookForAddedAndRemovedEntities [
{ #category : #'run-entities' }
FamixDiffResolver >> lookForMovedEntitiesInUnmatchedEntities [

^ self moveMatchesFrom: (self entitiesToMatchIn: self baseModel) to: (self entitiesToMatchIn: self targetModel)
| unmatchedBasedEntities unmatchedTargetEntities |
unmatchedBasedEntities := self topEntitiesToMatchIn: self baseModel.
unmatchedTargetEntities := self topEntitiesToMatchIn: self targetModel.
[
| baseTodo targetTodo |
baseTodo := self topEntitiesToMatchIn: self baseModel ignoringParentsIn: unmatchedBasedEntities.
targetTodo := self topEntitiesToMatchIn: self targetModel ignoringParentsIn: unmatchedTargetEntities.

((self moveMatchesFrom: baseTodo to: unmatchedTargetEntities) or: [
(self moveMatchesFrom: baseTodo to: targetTodo) or: [ self moveMatchesFrom: unmatchedBasedEntities to: targetTodo ] ]) ifTrue: [ ^ true ].

unmatchedBasedEntities addAll: baseTodo.
unmatchedTargetEntities addAll: targetTodo.

baseTodo isEmpty or: [ targetTodo isEmpty ] ] whileFalse.

^ false
]

{ #category : #testing }
Expand Down Expand Up @@ -369,6 +393,13 @@ FamixDiffResolver >> topEntitiesToMatchIn: aModel [
^ (self entitiesToMatchIn: aModel) select: [ :entity | self hasParentMatched: entity ]
]

{ #category : #'run-entities' }
FamixDiffResolver >> topEntitiesToMatchIn: aModel ignoringParentsIn: aCollection [

^ (self entitiesToMatchIn: aModel) select: [ :entity |
(aCollection includes: entity) not and: [ self hasParentMatched: entity ignoringParentsIn: aCollection ] ]
]

{ #category : #'run-entities' }
FamixDiffResolver >> updateProgressBarOf: job [

Expand Down
12 changes: 12 additions & 0 deletions src/Famix-Diff-Core/FamixDiffResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ FamixDiffResult >> entityChanges [
^ self reject: [ :change | change isForAssociation ]
]

{ #category : #accessing }
FamixDiffResult >> moves [

^ self select: [ :change | change isMove ]
]

{ #category : #accessing }
FamixDiffResult >> realChanges [
"I return all the changes actually representing a change, rejecting identical changes."
Expand All @@ -67,6 +73,12 @@ FamixDiffResult >> removals [
^ self select: [ :change | change isRemoval ]
]

{ #category : #accessing }
FamixDiffResult >> renames [

^ self select: [ :change | change isRename ]
]

{ #category : #private }
FamixDiffResult >> species [

Expand Down

0 comments on commit 9534e6d

Please sign in to comment.