Skip to content

Commit

Permalink
Fix category methods and add some refactory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin777 committed Dec 3, 2020
1 parent fc92353 commit 601a6b7
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ RBAbstractClassVariableTest >> testInheritedName [
class: RBBasicLintRuleTestData)
]

{ #category : #'failure tests' }
RBAbstractClassVariableTest >> testInvalidClass [
self shouldFail: (RBAbstractClassVariableRefactoring
variable: #DependentsFields
class: Object)
]

{ #category : #'failure tests' }
RBAbstractClassVariableTest >> testMetaClassFailure [
self shouldFail: (RBAbstractClassVariableRefactoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#category : #'Refactoring-Tests-Core'
}

{ #category : #tests }
{ #category : #'failure tests' }
RBApplyClassDeprecationRefactoringTest >> testBadName [
self
shouldFail: (RBApplyClassDeprecationRefactoring
Expand All @@ -15,7 +15,7 @@ RBApplyClassDeprecationRefactoringTest >> testBadName [
to: #'Ob ject')
]

{ #category : #tests }
{ #category : #'failure tests' }
RBApplyClassDeprecationRefactoringTest >> testMetaClassFailure [
self
shouldFail: (RBApplyClassDeprecationRefactoring rename: self class class to: #Foo)
Expand Down
9 changes: 9 additions & 0 deletions src/Refactoring-Tests-Core/RBExtractToTemporaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ RBExtractToTemporaryTest >> testExtractToTemporaryWithDuplicates [
^ answer')
]

{ #category : #'failure tests' }
RBExtractToTemporaryTest >> testNoValidNameOfTemp [
self shouldFail: (RBExtractToTemporaryRefactoring
extract: (51 to: 60)
to: 'collection'
from: #modifiesCollection
in: RBRefactoryTestDataApp)
]

{ #category : #'failure tests' }
RBExtractToTemporaryTest >> testNonExistantSelector [
self shouldFail: (RBExtractToTemporaryRefactoring
Expand Down
6 changes: 3 additions & 3 deletions src/Refactoring-Tests-Core/RBInlineTemporaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RBInlineTemporaryTest >> testInlineTemporary [
bar')
]

{ #category : #tests }
{ #category : #'failure tests' }
RBInlineTemporaryTest >> testInlineTemporaryBadInterval [
self
shouldFail:
Expand All @@ -30,7 +30,7 @@ RBInlineTemporaryTest >> testInlineTemporaryBadInterval [
in: RBRefactoryTestDataApp)
]

{ #category : #tests }
{ #category : #'failure tests' }
RBInlineTemporaryTest >> testInlineTemporaryMutlipleAssignment [
self
shouldFail:
Expand All @@ -40,7 +40,7 @@ RBInlineTemporaryTest >> testInlineTemporaryMutlipleAssignment [
in: RBRefactoryTestDataApp)
]

{ #category : #tests }
{ #category : #'failure tests' }
RBInlineTemporaryTest >> testInlineTemporaryReadBeforeWritten [
self
shouldFail:
Expand Down
14 changes: 12 additions & 2 deletions src/Refactoring-Tests-Core/RBMoveVariableDefinitionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Class {
#category : #'Refactoring-Tests-Core'
}

{ #category : #'failure tests' }
RBMoveVariableDefinitionTest >> testInvalidSelector [
self
shouldFail:
(RBMoveVariableDefinitionRefactoring
bindTight: (21 to: 24)
in: RBRefactoryTestDataApp
selector: #caller3)
]

{ #category : #tests }
RBMoveVariableDefinitionTest >> testMoveDefinition [
| refactoring |
Expand Down Expand Up @@ -47,7 +57,7 @@ RBMoveVariableDefinitionTest >> testMoveDefinitionIntoBlockThatIsAReceiverOfACas
yourself')
]

{ #category : #tests }
{ #category : #'failure tests' }
RBMoveVariableDefinitionTest >> testNoMoveDefinition [
self
shouldFail:
Expand All @@ -57,7 +67,7 @@ RBMoveVariableDefinitionTest >> testNoMoveDefinition [
selector: #noMoveDefinition)
]

{ #category : #tests }
{ #category : #'failure tests' }
RBMoveVariableDefinitionTest >> testNonExistantName [
self
shouldFail:
Expand Down
40 changes: 14 additions & 26 deletions src/Refactoring-Tests-Core/RBPullUpMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Class {
}

{ #category : #tests }
RBPullUpMethodTest >> testPullUpAndCopyDown [
| class |
RBPullUpMethodTest >> addClassHierarchy [
model
defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
Expand All @@ -15,6 +14,12 @@ RBPullUpMethodTest >> testPullUpAndCopyDown [
defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
]

{ #category : #tests }
RBPullUpMethodTest >> testPullUpAndCopyDown [
| class |
self addClassHierarchy.
class := model classNamed: #Foo1.
class compile: 'yourself ^1' classified: #(#accessing).
self proceedThroughWarning: [ self executeRefactoring: (RBPullUpMethodRefactoring
Expand Down Expand Up @@ -47,13 +52,10 @@ RBPullUpMethodTest >> testPullUpClassMethod [
{ #category : #tests }
RBPullUpMethodTest >> testPullUpInAHighHierarchyClass [
| class superClass |
model
defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.

self addClassHierarchy .
class := model classNamed: #Foo1.
self addClassHierarchy.
superClass := model classNamed: #SomeClass .
class compile: 'example ^1' classified: #(#accessing).
self executeRefactoring: (RBPullUpMethodRefactoring
Expand Down Expand Up @@ -131,7 +133,7 @@ RBPullUpMethodTest >> testPullUpWhenSuperClassDoesNotDirectlyImplement [
[ :methodPair | class compile: methodPair first classified: methodPair last ] ].
self
shouldntWarn:
(RBPullUpMethodRefactoring
(RBPullUpMethodRefactoring
model: model
pullUp: #(#foo)
from: (model classNamed: #ClassC))
Expand All @@ -140,14 +142,7 @@ RBPullUpMethodTest >> testPullUpWhenSuperClassDoesNotDirectlyImplement [
{ #category : #'failure tests' }
RBPullUpMethodTest >> testPullUpWithInvalidSuperSend [
| class |
model
defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
self addClassHierarchy .
(model classNamed: #Foo2) compile: 'yourself ^super yourself + 1'
classified: #(#accessing).
class := model classNamed: #Foo1.
Expand All @@ -159,7 +154,7 @@ RBPullUpMethodTest >> testPullUpWithInvalidSuperSend [
]

{ #category : #'failure tests' }
RBPullUpMethodTest >> testPullUpWithMethodThatCannotBePushedDown [
RBPullUpMethodTest >> testPullUpWithMethodThatCannotBePullUp [
model
defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''.
(model classNamed: #SomeClass) compile: 'yourself ^54'
Expand All @@ -173,17 +168,10 @@ RBPullUpMethodTest >> testPullUpWithMethodThatCannotBePushedDown [
{ #category : #'failure tests' }
RBPullUpMethodTest >> testPullUpWithSuperSendThatCannotBeCopiedDown [
| class |
model
defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''.
self addClassHierarchy.
(model classNamed: #Object) compile: 'foo ^3' classified: #(#accessing).
model
defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
(model classNamed: #Subclass) compile: 'foo ^super foo'
classified: #(#accessing).
model
defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
(class := model classNamed: #Foo2) compile: 'foo ^1'
classified: #(#accessing).
self shouldFail: (RBPullUpMethodRefactoring
Expand Down
19 changes: 19 additions & 0 deletions src/Refactoring-Tests-Core/RBPushDownMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ RBPushDownMethodTest >> testPushDownMethodOnNonAbstractClass [
self shouldFail: refactoring
]

{ #category : #'failure tests' }
RBPushDownMethodTest >> testPushDownMethodSubclassesReferToSelector [
| refactoring |
model
defineClass: 'Object subclass: #Superclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Superclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
model
defineClass: 'Superclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''.
(model classNamed: #Superclass) compile: 'yourself ^1' classified: #(#accessing).
(model classNamed: #Foo1) compile: 'method1 ^super yourself' classified: #(#accessing).

refactoring := RBPushDownMethodRefactoring
model: model
pushDown: #(#yourself)
from: (model classNamed: #Superclass).
self shouldFail: refactoring.
]

{ #category : #tests }
RBPushDownMethodTest >> testPushDownMethodThatReferencesPoolDictionary [
| refactoring class parseTree |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ RBRemoveHierarchyMethodTest >> testRemoveMethod [
self deny: ((refactoring model classNamed: #RBSharedPoolForTestData2) directlyDefinesMethod: selectors first)
]

{ #category : #tests }
{ #category : #'failure tests' }
RBRemoveHierarchyMethodTest >> testRemoveNonExistantMethod [
self shouldFail: (RBRemoveHierarchyMethodRefactoring
removeMethods: #(#msg7 )
from: RBBasicLintRuleTestData)
]

{ #category : #tests }
{ #category : #'failure tests' }
RBRemoveHierarchyMethodTest >> testRemoveReferenced [
self shouldFail: (RBRemoveHierarchyMethodRefactoring
removeMethods: #(#msg1 )
Expand Down
7 changes: 7 additions & 0 deletions src/Refactoring-Tests-Core/RBRemoveMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ RBRemoveMethodTest >> testRemoveMethod [
self deny: ((refactoring model classNamed: #RBRefactoryTestDataApp) directlyDefinesMethod: selectors first)
]

{ #category : #'failure tests' }
RBRemoveMethodTest >> testRemoveNonExistingMethod [
self shouldFail: (RBRemoveMethodRefactoring
removeMethods: #(#nonExistingMethod )
from: RBBasicLintRuleTestData)
]

{ #category : #'failure tests' }
RBRemoveMethodTest >> testRemoveReferenced [
self shouldFail: (RBRemoveMethodRefactoring
Expand Down
14 changes: 14 additions & 0 deletions src/Refactoring-Tests-Core/RBRemoveParameterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ RBRemoveParameterTest >> testPrimitiveMethods [
self shouldFail: refactoring
]

{ #category : #'failure tests' }
RBRemoveParameterTest >> testReferenceArgument [
| refactoring |
(model classNamed: #Object)
compile: 'methWith: arg1 ^ arg1 * 8'
classified: #(#accessing).
refactoring := RBRemoveParameterRefactoring
model: model
removeParameter: 'arg1'
in: Object
selector: #methWith:.
self shouldFail: refactoring
]

{ #category : #tests }
RBRemoveParameterTest >> testRemoveParameter [
| refactoring class |
Expand Down
20 changes: 16 additions & 4 deletions src/Refactoring-Tests-Core/RBRenameMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ RBRenameMethodTest >> testRenamePermuteArgs [
permutation: #(2 1 ).
self executeRefactoring: refactoring.
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self assert: (class parseTreeFor: ('rename:' , 'two:') asSymbol) equals: (self parseMethod: 'rename: argumentMethod two: this ^self printString, this, argumentMethod').
self assert: (class parseTreeFor: #exampleCall) equals: (self parseMethod: 'exampleCall <sampleInstance> ^self rename: 2 two: 1')
self assert: (class parseTreeFor: ('rename:' , 'two:') asSymbol)
equals: (self parseMethod: 'rename: argumentMethod two: this ^self printString, this, argumentMethod').
self assert: (class parseTreeFor: #exampleCall)
equals: (self parseMethod: 'exampleCall <sampleInstance> ^self rename: 2 two: 1')
]

{ #category : #tests }
Expand Down Expand Up @@ -112,9 +114,19 @@ RBRenameMethodTest >> testRenameTestMethod1 [
permutation: (1 to: 0).
self proceedThroughWarning: [ self executeRefactoring: refactoring ].
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self assert: (class parseTreeFor: #testMethod2) equals: (self parseMethod: 'testMethod2
self assert: (class parseTreeFor: #testMethod2)
equals: (self parseMethod: 'testMethod2
^self testMethod2 , ([:each | each testMethod2] value: #(#(#testMethod2) 2 #testMethod2))').
self assert: ((refactoring model classNamed: #RBBasicLintRuleTestData) parseTreeFor: #classBlock:) equals: (self parseMethod: 'classBlock: aBlock
self assert: ((refactoring model classNamed: #RBBasicLintRuleTestData) parseTreeFor: #classBlock:) equals: (self parseMethod: 'classBlock: aBlock
classBlock := aBlock testMethod2').
self deny: (class directlyDefinesMethod: ('test' , 'Method1') asSymbol)
]

{ #category : #'failure tests' }
RBRenameMethodTest >> testWithNonCorrectNumberOfArgs [
self shouldFail: (RBRenameMethodRefactoring
renameMethod: #checkClass:
in: RBBasicLintRuleTestData
to: #checkClass
permutation: (1 to: 1))
]
28 changes: 28 additions & 0 deletions src/Refactoring-Tests-Core/RBRenameTemporaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ RBRenameTemporaryTest >> testBadInterval [
renameTemporaryFrom: (14 to: 17)
to: 'asdf'
in: RBRefactoryTestDataApp
selector: #testMethod).
self
shouldFail:
(RBRenameArgumentOrTemporaryRefactoring
renameTemporaryFrom: (17 to: 14)
to: 'asdf'
in: RBRefactoryTestDataApp
selector: #testMethod).
self
shouldFail:
(RBRenameArgumentOrTemporaryRefactoring
renameTemporaryFrom: (19 to: 24)
to: 'asdf'
in: RBRefactoryTestDataApp
selector: #testMethod)
]

Expand Down Expand Up @@ -65,6 +79,20 @@ RBRenameTemporaryTest >> testModelBadName [
selector: #aMethod:)
]

{ #category : #tests }
RBRenameTemporaryTest >> testRenameArg [
| refactoring |
refactoring := RBRenameArgumentOrTemporaryRefactoring
renameTemporaryFrom: (7 to: 13)
to: 'asdf'
in: RBLintRuleTestData
selector: #name:.
self executeRefactoring: refactoring.

self assert: ((refactoring model classNamed: #RBLintRuleTestData) parseTreeFor: #name:) equals: (self parseMethod: 'name: asdf
name := asdf')
]

{ #category : #tests }
RBRenameTemporaryTest >> testRenameTemporary [
| refactoring |
Expand Down
6 changes: 3 additions & 3 deletions src/Refactoring-Tests-Core/RBReplaceMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#category : #'Refactoring-Tests-Core'
}

{ #category : #tests }
{ #category : #'failure tests' }
RBReplaceMethodTest >> testNotUnderstandNewSelector [
self shouldFail: (RBReplaceMethodRefactoring
replaceCallMethod: #checkClass:
Expand All @@ -13,7 +13,7 @@ RBReplaceMethodTest >> testNotUnderstandNewSelector [
permutation: (1 to: 1))
]

{ #category : #tests }
{ #category : #'failure tests' }
RBReplaceMethodTest >> testNotUnderstandSelector [
self shouldFail: (RBReplaceMethodRefactoring
replaceCallMethod: #checkClass123:
Expand Down Expand Up @@ -41,7 +41,7 @@ RBReplaceMethodTest >> testReplaceMethod [
self assert: count equals: (model allReferencesTo: #anInstVar:) size
]

{ #category : #tests }
{ #category : #'failure tests' }
RBReplaceMethodTest >> testSelectorsNotHaveSameNumberOfArgs [
self shouldFail: (RBReplaceMethodRefactoring
replaceCallMethod: #checkClass:
Expand Down
Loading

0 comments on commit 601a6b7

Please sign in to comment.