Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Debugger-CLI/NumericHistoryHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"
""Handles command !<anInteger> and return (if it exists) the command related to the number

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esteban I do not know if this changes is wished or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crap, not... that sneaked in when commiting :P

ex : !-2 returns the second last command
!2 returns the second command ""
"
Class {
#name : 'NumericHistoryHandler',
#superclass : 'DebuggerHistoryHandler',
#category : 'Debugger-CLI',
#package : 'Debugger-CLI'
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ RBBrowserEnvironmentTest >> testBrowserEnvironment [

{ #category : 'tests - environments' }
RBBrowserEnvironmentTest >> testClassEnvironment [

| aClassEnvironment |
aClassEnvironment := RBClassEnvironment onEnvironment: universalEnvironment classes: (Array with: Object with: Object class).
aClassEnvironment := RBClassEnvironment
onEnvironment: universalEnvironment
classes: (Array with: Object with: Object class).
self universalTestFor: aClassEnvironment.
self deny: universalEnvironment isClassEnvironment.
self assert: aClassEnvironment isClassEnvironment.
self assert: aClassEnvironment packages size equals: 1.
self deny: (universalEnvironment isClassEnvironment).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need the parentheses.

self assert: (aClassEnvironment isClassEnvironment).
self assert: (aClassEnvironment packages size) equals: 1.
self assert: (aClassEnvironment implementorsOf: #printString) numberSelectors equals: 1.

self assert: (RBClassEnvironment class: Class) selectors size
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-UI-Tests/ReDriverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ ReDriverTest >> setUpDriver: driver [

driver previewPresenterClass: StRefactoringPreviewPresenterMock.
driver selectDialogForBreakingChanges: StSelectDialogMock new.
driver informDialog: StInformDialogMock new.
driver informDialog: StInformDialogMock new
]
14 changes: 6 additions & 8 deletions src/Refactoring-UI-Tests/ReDuplicateClassDriverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,17 @@ ReDuplicateClassDriverTest >> testDuplicateClass [
{ #category : 'tests' }
ReDuplicateClassDriverTest >> testDuplicateClassInIncompleteModelFails [

| driver rbClass |
| driver |
testingEnvironment := RBClassEnvironment classes: { ReClassToBeDuplicated }.
driver := ReDuplicateClassDriver className:
ReClassToBeDuplicated name.
driver := ReDuplicateClassDriver className: ReClassToBeDuplicated name.

self setUpMocksOn: driver.

driver informDialog: StInformDialogMock new.
driver application: StApplicationForRefactorDriverMock new.
driver scopes: { testingEnvironment }.
rbClass := testingEnvironment classes anyOne.

self
should: [ driver runRefactoring ]
raise: RBRefactoringError
driver runRefactoring.
self assert: (driver application shownMessage includesSubstring: 'missing from the model')
]

{ #category : 'tests' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,49 @@ ReInsertSubclassBeSiblingDriverTest >> testAddSingleSubclassToDifferentPackage [

self assertSubclassesOf: rbClass
]

{ #category : 'tests' }
ReInsertSubclassBeSiblingDriverTest >> testAddSingleSubclassWithExistingClassNameInformsUser [

| driver |
driver := ReInsertSubclassDriver new.

self setUpDriver: driver.

driver application: StApplicationForRefactorDriverMock new.

driver
beSibling;
superclass: self superclassToAddSubclass;
scopes: { testingEnvironment };
subclass: self superclassToAddSubclass name.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'already exists').
self assert: self superclassToAddSubclass subclasses size equals: 2
]

{ #category : 'tests' }
ReInsertSubclassBeSiblingDriverTest >> testAddSingleSubclassWithInvalidClassNameInformsUser [

| driver |
driver := ReInsertSubclassDriver new.

self setUpDriver: driver.

driver application: StApplicationForRefactorDriverMock new.

driver
beSibling;
superclass: self superclassToAddSubclass;
scopes: { testingEnvironment };
subclass: 'noCapital'.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'is not a valid class name').
self assert: self superclassToAddSubclass subclasses size equals: 2
]
44 changes: 44 additions & 0 deletions src/Refactoring-UI-Tests/ReInsertSubclassDriverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,47 @@ ReInsertSubclassDriverTest >> testInsertSubclassInADifferentPackage [
assert: driver refactoring changes changes first package
equals: RBAbstractClass packageName
]

{ #category : 'tests' }
ReInsertSubclassDriverTest >> testInsertSubclassWithExistingClassNameInformsUser [

| driver |
driver := ReInsertSubclassDriver new.

self setUpDriver: driver.

driver application: StApplicationForRefactorDriverMock new.

driver
superclass: self superclassToAddSubclass;
scopes: { testingEnvironment };
subclass: self superclassToAddSubclass name.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'already exists').
self assert: self superclassToAddSubclass subclasses size equals: 2
]

{ #category : 'tests' }
ReInsertSubclassDriverTest >> testInsertSubclassWithInvalidClassNameInformsUser [

| driver |
driver := ReInsertSubclassDriver new.

self setUpDriver: driver.

driver application: StApplicationForRefactorDriverMock new.

driver
superclass: self superclassToAddSubclass;
scopes: { testingEnvironment };
subclass: 'noCapital'.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'is not a valid class name').
self assert: self superclassToAddSubclass subclasses size equals: 2
]
65 changes: 65 additions & 0 deletions src/Refactoring-UI-Tests/ReInsertSuperclassDriverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,71 @@ ReInsertSuperclassDriverTest >> testInsertSuperclass [
self assert: rbLeafClass superclass name equals: self newSuperclassName
]

{ #category : 'tests' }
ReInsertSuperclassDriverTest >> testInsertSuperclassWithExistingClassNameInformsUser [

| driver |
driver := ReInsertSuperclassDriver new.

self setUpDriver: driver.

driver application: StApplicationForRefactorDriverMock new.

driver
superclass: self theClassToAddASuperclass;
scopes: { testingEnvironment };
subclass: self theClassToAddASuperclass name.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'already exists').
self assert: self theClassToAddASuperclass superclass name equals: #RBRootClassForInsertingSubclasses
]

{ #category : 'tests' }
ReInsertSuperclassDriverTest >> testInsertSuperclassWithInvalidClassNameInformsUser [

| driver |
driver := ReInsertSuperclassDriver new.
self setUpDriver: driver.
driver application: StApplicationForRefactorDriverMock new.

driver
superclass: self theClassToAddASuperclass;
scopes: { testingEnvironment };
subclass: 'noCapital'.

driver runRefactoring.

self assert: driver refactoring failedApplicabilityPreconditions size equals: 1.
self assert: (driver application shownMessage includesSubstring: 'is not a valid class name').
self assert: self theClassToAddASuperclass superclass name equals: #RBRootClassForInsertingSubclasses
]

{ #category : 'tests' }
ReInsertSuperclassDriverTest >> testInsertSuperclassWithoutExplicitParent [
| driver rbLeafClass |

driver := ReInsertSuperclassDriver new.

self setUpDriver: driver.
driver
superclass: self theClassToAddASuperclass;
scopes: { testingEnvironment };
subclass: self newSuperclassName.
rbLeafClass := driver superclass.

self assert: rbLeafClass subclasses size equals: 0.

driver runRefactoring.

self assert: driver refactoring changes changes size equals: 2.
self assert: rbLeafClass subclasses size equals: 0.
self assert: rbLeafClass superclass subclasses size equals: 1.
self assert: rbLeafClass superclass name equals: self newSuperclassName
]

{ #category : 'tests' }
ReInsertSuperclassDriverTest >> theClassToAddASuperclass [
"Answer the <Class> which will be superclassed"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"
A mock application used by refactoring driver tests.

It records the last message received through #inform: so tests can assert the feedback reported to the user without opening any dialog. It is installed on a driver through the #application: hook.
"
Class {
#name : 'StApplicationForRefactorDriverMock',
#superclass : 'Object',
#instVars : [
'shownMessage'
],
#category : 'Refactoring-UI-Tests',
#package : 'Refactoring-UI-Tests'
}

{ #category : 'interaction' }
StApplicationForRefactorDriverMock >> inform: aString [

shownMessage := aString
]

{ #category : 'accessing' }
StApplicationForRefactorDriverMock >> shownMessage [

^ shownMessage
]
11 changes: 10 additions & 1 deletion src/Refactoring-UI-Tests/StInformDialogMock.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Class {
#name : 'StInformDialogMock',
#superclass : 'Object',
#instVars : [
'shownMessage'
],
#category : 'Refactoring-UI-Tests',
#package : 'Refactoring-UI-Tests'
}
Expand All @@ -15,13 +18,19 @@ StInformDialogMock >> label: aString [
{ #category : 'accessing' }
StInformDialogMock >> message: aString [

^ 'nothing'
shownMessage := aString
]

{ #category : 'api - showing' }
StInformDialogMock >> openModal [
]

{ #category : 'accessing' }
StInformDialogMock >> shownMessage [

^ shownMessage
]

{ #category : 'accessing' }
StInformDialogMock >> text: aString [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ StRefactoringAddClassPresenterTest >> newPresenter [
yourself)
]

{ #category : 'tests' }
StRefactoringAddClassPresenterTest >> testClassNameInputIsRecordedInDriver [
| driver |

driver := presenter instVarNamed: 'driver'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using an accessor?
It makes sense that we can access the driver of a presenter.

@estebanlm estebanlm Sep 11, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. It was not me who did that !

(presenter instVarNamed: 'textInput') text: 'Object'.
self assert: driver subclass equals: 'Object'
]

{ #category : 'tests' }
StRefactoringAddClassPresenterTest >> testCommentTemplateActivationFillsComment [

Expand Down
6 changes: 2 additions & 4 deletions src/Refactoring-UI/ReInsertSuperclassDriver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ ReInsertSuperclassDriver >> gatherUserInput [

{ #category : 'configuration' }
ReInsertSuperclassDriver >> instantiateRefactoring [
"self ensureSuperclassInModel."

^ (RBInsertNewClassRefactoring className: self subclass asString)
model: model;
Expand Down Expand Up @@ -123,10 +122,9 @@ ReInsertSuperclassDriver >> requestClass [
ReInsertSuperclassDriver >> scopes: refactoringScopes [

scopes := refactoringScopes.

model := self refactoringScopeOn: scopes first.
superclass := model classObjectFor: superclass

superclass := model classObjectFor: superclass.
superclassParent ifNil: [ superclassParent := superclass superclass ]
]

{ #category : 'accessing' }
Expand Down
23 changes: 16 additions & 7 deletions src/Refactoring-UI/ReInteractionDriver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ ReInteractionDriver >> defaultSelectDialog [
^ self application newSelect
]

{ #category : 'execution' }
ReInteractionDriver >> executeRefactoring [
"Configures the refactoring, gathers user input and applies the changes."
Comment thread
estebanlm marked this conversation as resolved.
Outdated

self configureRefactoring.
self gatherUserInput ifFalse: [ ^ self "user abandons" ].
self hasFailedApplicabilityPreconditions ifTrue: [ ^ self "applicability failed" ].

self hasFailedBehaviorPreservingPreconditions
ifTrue: [ self handleBreakingChanges ]
ifFalse: [ self applyChanges ]
]

{ #category : 'ui - dialogs' }
ReInteractionDriver >> failedPreconditionsErrorString [

Expand Down Expand Up @@ -350,13 +363,9 @@ ReInteractionDriver >> requestDialog: aDialog [
{ #category : 'execution' }
ReInteractionDriver >> runRefactoring [

self configureRefactoring.
self gatherUserInput ifFalse: [ ^ self "user abandons" ].
self hasFailedApplicabilityPreconditions ifTrue: [ ^ self "applicability failed" ].
self hasFailedBehaviorPreservingPreconditions
ifTrue: [ self handleBreakingChanges ]
ifFalse: [ self applyChanges ].

[ self executeRefactoring ]
on: Error
do: [ :e | self inform: 'The refactoring could not be executed: ' , e messageText ]
]

{ #category : 'accessing' }
Expand Down
7 changes: 2 additions & 5 deletions src/Refactoring-UI/StRefactoringAddClassPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ StRefactoringAddClassPresenter >> defaultLayout [
StRefactoringAddClassPresenter >> initializeClassNamePresenter [

textInput := self newTextInput
whenTextChangedDo: [ : text |
(Smalltalk globals hasClassNamed: text asSymbol)
ifTrue: [ self inform: 'Class ' , text asString , ' already exists' ]
ifFalse: [ driver subclass: self newClassName ] ];
yourself.
whenTextChangedDo: [ :text | driver subclass: self newClassName ];
yourself
]

{ #category : 'initialization' }
Expand Down