Skip to content

Commit

Permalink
Did migration with the following renamings (order is important):
Browse files Browse the repository at this point in the history
#name -> #dynamicName.
#description -> #dynamicDescription.
#basicName -> #name.
#basicDescription -> #description.

Also did some renamings for test methods.
  • Loading branch information
juliendelplanque committed Aug 14, 2019
1 parent 51d5e12 commit 1a8f4e8
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 105 deletions.
25 changes: 25 additions & 0 deletions src/Commander2-Deprecations/CmCommandDecorator.extension.st
@@ -0,0 +1,25 @@
Extension { #name : #CmCommandDecorator }

{ #category : #'*Commander2-Deprecations' }
CmCommandDecorator >> basicDescription [
self deprecated: 'Use #description instead.' transformWith: '`@receiver basicDescription' -> '`@receiver description'.
^ self description
]

{ #category : #'*Commander2-Deprecations' }
CmCommandDecorator >> basicDescription: anObject [
self deprecated: 'Use #description: instead.' transformWith: '`@receiver basicDescription: `@arg' -> '`@receiver description: `@arg'.
^ self description: anObject
]

{ #category : #'*Commander2-Deprecations' }
CmCommandDecorator >> basicName [
self deprecated: 'Use #name instead.' transformWith: '`@receiver basicName' -> '`@receiver name'.
^ self name
]

{ #category : #'*Commander2-Deprecations' }
CmCommandDecorator >> basicName: anObject [
self deprecated: 'Use #name: instead.' transformWith: '`@receiver basicName: `@arg' -> '`@receiver name: `@arg'.
^ self name: anObject
]
@@ -0,0 +1,25 @@
Extension { #name : #CmTWithBasicNameAndDescription }

{ #category : #'*Commander2-Deprecations' }
CmTWithBasicNameAndDescription >> basicDescription [
self deprecated: 'Use #description instead.' transformWith: '`@receiver basicDescription' -> '`@receiver description'.
^ self description
]

{ #category : #'*Commander2-Deprecations' }
CmTWithBasicNameAndDescription >> basicDescription: anObject [
self deprecated: 'Use #description: instead.' transformWith: '`@receiver basicDescription: `@arg' -> '`@receiver description: `@arg'.
^ self description: anObject
]

{ #category : #'*Commander2-Deprecations' }
CmTWithBasicNameAndDescription >> basicName [
self deprecated: 'Use #name instead.' transformWith: '`@receiver basicName' -> '`@receiver name'.
^ self name
]

{ #category : #'*Commander2-Deprecations' }
CmTWithBasicNameAndDescription >> basicName: anObject [
self deprecated: 'Use #name: instead.' transformWith: '`@receiver basicName: `@arg' -> '`@receiver name: `@arg'.
^ self name: anObject
]
21 changes: 13 additions & 8 deletions src/Commander2-Tests/CmCommandDecoratorTest.class.st
Expand Up @@ -17,18 +17,13 @@ CmCommandDecoratorTest >> setUp [
commandToBeDecorated := CmCommand new. commandToBeDecorated := CmCommand new.


commandToBeDecorated commandToBeDecorated
basicName: 'command for test'; name: 'command for test';
basicDescription: 'This command is only cerated for the purpose of unit tests.'; description: 'This command is only cerated for the purpose of unit tests.';
context: Object new. context: Object new.


decorator := CmCommandDecorator decorate: commandToBeDecorated decorator := CmCommandDecorator decorate: commandToBeDecorated
] ]


{ #category : #test }
CmCommandDecoratorTest >> testBasicName [
self assert: decorator basicName equals: commandToBeDecorated basicName
]

{ #category : #test } { #category : #test }
CmCommandDecoratorTest >> testContext [ CmCommandDecoratorTest >> testContext [
self assert: decorator context equals: commandToBeDecorated context self assert: decorator context equals: commandToBeDecorated context
Expand All @@ -47,7 +42,17 @@ CmCommandDecoratorTest >> testDecoratedCommand [


{ #category : #test } { #category : #test }
CmCommandDecoratorTest >> testDescription [ CmCommandDecoratorTest >> testDescription [
self assert: decorator basicDescription equals: commandToBeDecorated basicDescription self assert: decorator description equals: commandToBeDecorated description
]

{ #category : #test }
CmCommandDecoratorTest >> testDynamicDescription [
self assert: decorator description equals: commandToBeDecorated description
]

{ #category : #test }
CmCommandDecoratorTest >> testDynamicName [
self assert: decorator dynamicName equals: commandToBeDecorated dynamicName
] ]


{ #category : #test } { #category : #test }
Expand Down
28 changes: 14 additions & 14 deletions src/Commander2-Tests/CmCommandTest.class.st
Expand Up @@ -13,16 +13,6 @@ CmCommandTest >> setUp [
command := CmFakeCommand new. command := CmFakeCommand new.
] ]


{ #category : #test }
CmCommandTest >> testBasicDescription [
self assert: command basicDescription equals: 'I am a fake command for testing purposes.'.
]

{ #category : #test }
CmCommandTest >> testBasicName [
self assert: command basicName equals: 'Fake command'.
]

{ #category : #test } { #category : #test }
CmCommandTest >> testCanBeExecuted [ CmCommandTest >> testCanBeExecuted [
command context: 0. "Need to set context before because the command expects it." command context: 0. "Need to set context before because the command expects it."
Expand All @@ -47,9 +37,21 @@ CmCommandTest >> testContext [


{ #category : #test } { #category : #test }
CmCommandTest >> testDescription [ CmCommandTest >> testDescription [
self assert: command description equals: 'I am a fake command for testing purposes.'.
]

{ #category : #test }
CmCommandTest >> testDynamicDescription [
command context: 42.

self assert: command dynamicDescription equals: command description , ' 42'
]

{ #category : #test }
CmCommandTest >> testDynamicName [
command context: 42. command context: 42.


self assert: command description equals: command basicDescription , ' 42' self assert: command dynamicName equals: command name , ' 42'
] ]


{ #category : #test } { #category : #test }
Expand All @@ -67,7 +69,5 @@ CmCommandTest >> testHasContext [


{ #category : #test } { #category : #test }
CmCommandTest >> testName [ CmCommandTest >> testName [
command context: 42. self assert: command name equals: 'Fake command'.

self assert: command name equals: command basicName , ' 42'
] ]
12 changes: 6 additions & 6 deletions src/Commander2-Tests/CmCommandsGroupTest.class.st
Expand Up @@ -19,14 +19,14 @@ CmCommandsGroupTest >> setUp [
super setUp. super setUp.
group := CmCommandGroup named: 'main group'. group := CmCommandGroup named: 'main group'.
firstCommand := CmBlockCommand new firstCommand := CmBlockCommand new
basicName: 'first command'; name: 'first command';
block: [ :x | x ]; block: [ :x | x ];
context: [ 1 ]; context: [ 1 ];
yourself. yourself.




subCommand1 := CmBlockCommand new subCommand1 := CmBlockCommand new
basicName: 'sub command 1'; name: 'sub command 1';
block: [ :x | x ]; block: [ :x | x ];
context: [ 11 ]; context: [ 11 ];
yourself. yourself.
Expand Down Expand Up @@ -96,7 +96,7 @@ CmCommandsGroupTest >> testInitialize [
| newGroup | | newGroup |
newGroup := CmCommandGroup new. newGroup := CmCommandGroup new.


self assert: newGroup basicName equals: CmCommandGroup defaultName. self assert: newGroup name equals: CmCommandGroup defaultName.
self assert: newGroup entries isEmpty self assert: newGroup entries isEmpty
] ]


Expand All @@ -106,7 +106,7 @@ CmCommandsGroupTest >> testRegisterCommandWithContext [
self deny: (group hasEntryNamed: 'second command'). self deny: (group hasEntryNamed: 'second command').


secondCommand := CmBlockCommand new secondCommand := CmBlockCommand new
basicName: 'second command'; name: 'second command';
block: [ :x | x ]; block: [ :x | x ];
context: 42; context: 42;
yourself. yourself.
Expand All @@ -123,7 +123,7 @@ CmCommandsGroupTest >> testRegisterCommandWithContextBlock [
self deny: (group hasEntryNamed: 'second command'). self deny: (group hasEntryNamed: 'second command').


secondCommand := CmBlockCommand new secondCommand := CmBlockCommand new
basicName: 'second command'; name: 'second command';
block: [ :x | x ]; block: [ :x | x ];
context: [ 42 ]; context: [ 42 ];
yourself. yourself.
Expand All @@ -133,7 +133,7 @@ CmCommandsGroupTest >> testRegisterCommandWithContextBlock [
self assert: (group commandOrGroupNamed: 'second command') equals: secondCommand. self assert: (group commandOrGroupNamed: 'second command') equals: secondCommand.


secondCommandWithSameName := CmBlockCommand new secondCommandWithSameName := CmBlockCommand new
basicName: 'second command'; name: 'second command';
block: [ :x | x ]; block: [ :x | x ];
context: [ ]; context: [ ];
yourself. yourself.
Expand Down
18 changes: 9 additions & 9 deletions src/Commander2-Tests/CmFakeCommand.class.st
Expand Up @@ -10,19 +10,19 @@ CmFakeCommand >> canBeExecuted [
] ]


{ #category : #accessing } { #category : #accessing }
CmFakeCommand >> description [ CmFakeCommand >> dynamicDescription [
^ super description , ' ' , self context asString ^ super dynamicDescription , ' ' , self context asString
]

{ #category : #accessing }
CmFakeCommand >> dynamicName [
^ super dynamicName , ' ' , self context asString
] ]


{ #category : #initialization } { #category : #initialization }
CmFakeCommand >> initialize [ CmFakeCommand >> initialize [
super initialize. super initialize.
self self
basicName: 'Fake command'; name: 'Fake command';
basicDescription: 'I am a fake command for testing purposes.' description: 'I am a fake command for testing purposes.'
]

{ #category : #accessing }
CmFakeCommand >> name [
^ super name , ' ' , self context asString
] ]
4 changes: 2 additions & 2 deletions src/Commander2/CmCommand.class.st
Expand Up @@ -58,6 +58,6 @@ CmCommand >> hasContext [
{ #category : #initialization } { #category : #initialization }
CmCommand >> initialize [ CmCommand >> initialize [
super initialize. super initialize.
self basicName: self class defaultName. self name: self class defaultName.
self basicDescription: self class defaultDescription self description: self class defaultDescription
] ]
40 changes: 20 additions & 20 deletions src/Commander2/CmCommandDecorator.class.st
Expand Up @@ -14,26 +14,6 @@ Class {
#category : #'Commander2-Commands' #category : #'Commander2-Commands'
} }


{ #category : #accessing }
CmCommandDecorator >> basicDescription [
^ self decoratedCommand basicDescription
]

{ #category : #accessing }
CmCommandDecorator >> basicDescription: aString [
self decoratedCommand basicDescription: aString
]

{ #category : #accessing }
CmCommandDecorator >> basicName [
^ self decoratedCommand basicName
]

{ #category : #accessing }
CmCommandDecorator >> basicName: aString [
self decoratedCommand basicName: aString
]

{ #category : #testing } { #category : #testing }
CmCommandDecorator >> canBeExecuted [ CmCommandDecorator >> canBeExecuted [
"This hook allows the command decide if it can be run with the context it holds or not. "This hook allows the command decide if it can be run with the context it holds or not.
Expand Down Expand Up @@ -72,6 +52,21 @@ CmCommandDecorator >> description [
^ self decoratedCommand description ^ self decoratedCommand description
] ]


{ #category : #accessing }
CmCommandDecorator >> description: aString [
self decoratedCommand description: aString
]

{ #category : #accessing }
CmCommandDecorator >> dynamicDescription [
^ self decoratedCommand dynamicDescription
]

{ #category : #accessing }
CmCommandDecorator >> dynamicName [
^ self decoratedCommand dynamicName
]

{ #category : #executing } { #category : #executing }
CmCommandDecorator >> execute [ CmCommandDecorator >> execute [
self decoratedCommand execute self decoratedCommand execute
Expand All @@ -81,3 +76,8 @@ CmCommandDecorator >> execute [
CmCommandDecorator >> name [ CmCommandDecorator >> name [
^ self decoratedCommand name ^ self decoratedCommand name
] ]

{ #category : #accessing }
CmCommandDecorator >> name: aString [
self decoratedCommand name: aString
]
16 changes: 8 additions & 8 deletions src/Commander2/CmCommandGroup.class.st
Expand Up @@ -29,7 +29,7 @@ CmCommandGroup class >> defaultName [
{ #category : #'instance creation' } { #category : #'instance creation' }
CmCommandGroup class >> named: aString [ CmCommandGroup class >> named: aString [
^ self new ^ self new
basicName: aString; name: aString;
yourself yourself
] ]


Expand All @@ -43,7 +43,7 @@ CmCommandGroup >> allCommands [


{ #category : #'public-api' } { #category : #'public-api' }
CmCommandGroup >> commandOrGroupNamed: aString [ CmCommandGroup >> commandOrGroupNamed: aString [
^ (entries detect: [ :commandOrRegister | commandOrRegister basicName = aString ]) ^ (entries detect: [ :commandOrRegister | commandOrRegister name = aString ])
] ]


{ #category : #'public-api' } { #category : #'public-api' }
Expand All @@ -56,8 +56,8 @@ CmCommandGroup >> ensureNotDuplicated: aCommandOrGroup [
"Check that aCommandOrGroup's #basicName is not already used by one of my entries. "Check that aCommandOrGroup's #basicName is not already used by one of my entries.
If it is, raises a CmDuplicatedEntryName error. If it is, raises a CmDuplicatedEntryName error.
" "
(self hasEntryNamed: aCommandOrGroup basicName) (self hasEntryNamed: aCommandOrGroup name)
ifTrue: [ CmDuplicatedEntryName signalEntryNamed: aCommandOrGroup basicName ] ifTrue: [ CmDuplicatedEntryName signalEntryNamed: aCommandOrGroup name ]
] ]


{ #category : #'public-api' } { #category : #'public-api' }
Expand Down Expand Up @@ -94,7 +94,7 @@ CmCommandGroup >> hasEntryNamed: aString [
"Returns true if one of my entries (command, registry, ...) is named aString. "Returns true if one of my entries (command, registry, ...) is named aString.
Else returns false. Else returns false.
" "
^ entries anySatisfy: [ :any | any basicName = aString ] ^ entries anySatisfy: [ :any | any name = aString ]
] ]


{ #category : #testing } { #category : #testing }
Expand All @@ -105,8 +105,8 @@ CmCommandGroup >> hasGroup: aCommandGroup [
{ #category : #initialization } { #category : #initialization }
CmCommandGroup >> initialize [ CmCommandGroup >> initialize [
super initialize. super initialize.
self basicName: self class defaultName. self name: self class defaultName.
self basicDescription: self class defaultDescription. self description: self class defaultDescription.
entries := OrderedCollection new entries := OrderedCollection new
] ]


Expand All @@ -132,7 +132,7 @@ CmCommandGroup >> register: aCommandOrGroup insteadOf: anotherCommandOrGroup [
| commandToReplaceIndex | | commandToReplaceIndex |
commandToReplaceIndex := self entriesIndexOf: anotherCommandOrGroup. commandToReplaceIndex := self entriesIndexOf: anotherCommandOrGroup.


((self commands collect: #basicName) \ { (entries at: commandToReplaceIndex) } includes: aCommandOrGroup name) ((self commands collect: #name) \ { (entries at: commandToReplaceIndex) } includes: aCommandOrGroup name)
ifTrue: [ CmDuplicatedEntryName signalEntryNamed: aCommandOrGroup name ]. ifTrue: [ CmDuplicatedEntryName signalEntryNamed: aCommandOrGroup name ].


entries at: commandToReplaceIndex put: aCommandOrGroup entries at: commandToReplaceIndex put: aCommandOrGroup
Expand Down

0 comments on commit 1a8f4e8

Please sign in to comment.