Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to write tests for a method equivalent tree checker.
- Loading branch information
1 parent
a81dbfe
commit c665858
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/Refactoring-DataForTesting/RBEquivalentMethodRootHolder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Class { | ||
#name : 'RBEquivalentMethodRootHolder', | ||
#superclass : 'Object', | ||
#category : 'Refactoring-DataForTesting-MiniHierarchy', | ||
#package : 'Refactoring-DataForTesting', | ||
#tag : 'MiniHierarchy' | ||
} | ||
|
||
{ #category : 'for tests' } | ||
RBEquivalentMethodRootHolder >> simpleMethodReturn [ | ||
|
||
^ 42 | ||
] |
19 changes: 19 additions & 0 deletions
19
src/Refactoring-DataForTesting/RBEquivalentMethodSubclassHolder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Class { | ||
#name : 'RBEquivalentMethodSubclassHolder', | ||
#superclass : 'RBEquivalentMethodRootHolder', | ||
#category : 'Refactoring-DataForTesting-MiniHierarchy', | ||
#package : 'Refactoring-DataForTesting', | ||
#tag : 'MiniHierarchy' | ||
} | ||
|
||
{ #category : 'for tests' } | ||
RBEquivalentMethodSubclassHolder >> anotherMethod: arg [ | ||
|
||
^ arg raisedTo: 5 | ||
] | ||
|
||
{ #category : 'for tests' } | ||
RBEquivalentMethodSubclassHolder >> simpleLocalMethodReturn [ | ||
|
||
^ 42 + 33 | ||
] |
50 changes: 50 additions & 0 deletions
50
src/Refactoring-Transformations-Tests/EquivalentTreeChecker.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Class { | ||
#name : 'EquivalentTreeChecker', | ||
#superclass : 'Object', | ||
#instVars : [ | ||
'selector', | ||
'class', | ||
'model' | ||
], | ||
#category : 'Refactoring-Transformations-Tests-Test', | ||
#package : 'Refactoring-Transformations-Tests', | ||
#tag : 'Test' | ||
} | ||
|
||
{ #category : 'query' } | ||
EquivalentTreeChecker >> allMethodsInHierarchy [ | ||
^ ((class withAllSuperclassesUntil: Object) | ||
flatCollect: [ :class | class methods]) | ||
] | ||
|
||
{ #category : 'as yet unclassified' } | ||
EquivalentTreeChecker >> allMethodsInHierarchyOf: aRBClass [ | ||
|
||
^ ((aRBClass withAllSuperclassesUntil: Object) | ||
flatCollect: [ :class | class methods collect: [ :each | each method ] ]) | ||
] | ||
|
||
{ #category : 'as yet unclassified' } | ||
EquivalentTreeChecker >> methodsToBeChecked [ | ||
|
||
^ (self allMethodsInHierarchyOf: self definingClass) reject: [ | ||
:m | m selector = selector ] | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
EquivalentTreeChecker >> model: aModel [ | ||
|
||
model := aModel | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
EquivalentTreeChecker >> on: aClass [ | ||
|
||
class := model classNamed: aClass name | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
EquivalentTreeChecker >> rbClassFor: aClass [ | ||
|
||
^ model classNamed: aClass name | ||
] |
45 changes: 45 additions & 0 deletions
45
src/Refactoring-Transformations-Tests/EquivalentTreeTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Class { | ||
#name : 'EquivalentTreeTest', | ||
#superclass : 'TestCase', | ||
#category : 'Refactoring-Transformations-Tests-Test', | ||
#package : 'Refactoring-Transformations-Tests', | ||
#tag : 'Test' | ||
} | ||
|
||
{ #category : 'tests' } | ||
EquivalentTreeTest >> testAllMethodsInHierarchy [ | ||
|
||
| checker allMethods model | | ||
model := RBNamespace new. | ||
checker := EquivalentTreeChecker new. | ||
checker model: model. | ||
checker on: RBEquivalentMethodSubclassHolder. | ||
|
||
allMethods := checker allMethodsInHierarchy. | ||
|
||
"pay attention that we want to have rbMethods" | ||
"pay attention rb-Methods are not cached so the includes: did not find them." | ||
self assert: | ||
((allMethods collect: [:each | each selector ]) | ||
includesAll: ((model classNamed: RBEquivalentMethodSubclassHolder name) methods collect: [:each | each selector])). | ||
|
||
self assert: | ||
((allMethods collect: [:each | each selector ]) | ||
includesAll: ((model classNamed: RBEquivalentMethodSubclassHolder superclass name) methods collect: [:each | each selector])). | ||
|
||
|
||
"since we did redefine supermethods, none of Object should be listed." | ||
self deny: | ||
((allMethods collect: [:each | each selector ]) | ||
includesAll: ((model classNamed: Object name) methods collect: [:each | each selector])). | ||
] | ||
|
||
{ #category : 'tests' } | ||
EquivalentTreeTest >> testSimpleLocalMethodReturn [ | ||
|
||
| checker| | ||
checker := EquivalentTreeChecker new. | ||
checker checkIfMethod: RBEquivalentMethodSubclassHolder>>#simpleLocalMethodReturn | ||
|
||
|
||
] |