-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a little strategy to manage filename generation.
Add a couple of tests to cover. Next step: should integrate the filenamer with the MD File.
- Loading branch information
Showing
6 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
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,49 @@ | ||
Class { | ||
#name : 'MDFileNameTest', | ||
#superclass : 'TestCase', | ||
#category : 'MicroEd-Tests', | ||
#package : 'MicroEd-Tests' | ||
} | ||
|
||
{ #category : 'tests' } | ||
MDFileNameTest >> testDefaultName [ | ||
|
||
self assert: MDFileNamer new defaultEmptyName equals: 'unnamed.md' | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDFileNameTest >> testDefaultNameSetDifferently [ | ||
|
||
| namer | | ||
namer := MDFileNamer new defaultEmptyName: 'Unknown.md'. | ||
|
||
self assert: namer newName equals: 'Unknown.md' | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDFileNameTest >> testDefaultNameSetDifferentlyDoesNotInfluenceNewNameBasedOn [ | ||
|
||
| namer | | ||
namer := MDFileNamer new defaultEmptyName: 'Unknown.md'. | ||
|
||
self assert: (namer newNameBasedOn: 'Toto.md') equals: 'Toto.md' | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDFileNameTest >> testNameWithNameAlreadyTagged [ | ||
|
||
| namer priorName name | | ||
namer := MDFileNamer new. | ||
priorName := 'Bla', namer separatorString, 'Unknown.md'. | ||
name := namer newNameBasedOn: priorName. | ||
|
||
self assert: name equals: priorName | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDFileNameTest >> testNewNameWithNoExtension [ | ||
|
||
| name | | ||
name := MDFileNamer new newNameBasedOn: 'Unknown'. | ||
self assert: name equals: 'Unknown.md' | ||
] |
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,49 @@ | ||
Class { | ||
#name : 'MDISOFileNameTest', | ||
#superclass : 'TestCase', | ||
#category : 'MicroEd-Tests', | ||
#package : 'MicroEd-Tests' | ||
} | ||
|
||
{ #category : 'tests' } | ||
MDISOFileNameTest >> testDefaultNameSetDifferently [ | ||
|
||
| namer | | ||
namer := ISOFileNamer new defaultEmptyName: 'Unknown.md'. | ||
|
||
self assert: namer newName equals: 'Unknown.md' | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDISOFileNameTest >> testNameWithNameAlreadyTagged [ | ||
|
||
| namer priorName name | | ||
namer := ISOFileNamer new. | ||
priorName := 'Bla', namer separatorString, 'Unknown.md'. | ||
name := namer newNameBasedOn: priorName. | ||
self assert: name equals: priorName | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDISOFileNameTest >> testNewName [ | ||
|
||
| namer | | ||
namer := ISOFileNamer new. | ||
namer date: (Date readFrom: '2024-11-02' readStream pattern: 'y-m-d'). | ||
|
||
self | ||
assert: (namer newNameBasedOn: 'Unknown.md') | ||
equals: '2024-11-02_Unknown.md' | ||
] | ||
|
||
{ #category : 'tests' } | ||
MDISOFileNameTest >> testNewNameWithNoExtension [ | ||
|
||
| namer | | ||
namer := ISOFileNamer new. | ||
namer date: (Date readFrom: '2024-11-02' readStream pattern: 'y-m-d'). | ||
|
||
self | ||
assert: (namer newNameBasedOn: 'Unknown') | ||
equals: '2024-11-02_Unknown.md' | ||
] |
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,35 @@ | ||
Class { | ||
#name : 'ISOFileNamer', | ||
#superclass : 'MDFileNamer', | ||
#instVars : [ | ||
'date' | ||
], | ||
#category : 'MicroEd', | ||
#package : 'MicroEd' | ||
} | ||
|
||
{ #category : 'naming' } | ||
ISOFileNamer >> date [ | ||
|
||
^ date ifNil: [ date := Date today ] | ||
] | ||
|
||
{ #category : 'naming' } | ||
ISOFileNamer >> date: aDate [ | ||
|
||
date := aDate | ||
] | ||
|
||
{ #category : 'naming' } | ||
ISOFileNamer >> newNameBasedOn: aString [ | ||
"Answer a String representing the receiver's file name" | ||
|
||
| aStringWithExtension | | ||
aStringWithExtension := self addExtensionIfNeeded: aString. | ||
^ (aStringWithExtension includesSubstring: '_') | ||
ifTrue: [ aStringWithExtension ] | ||
ifFalse: [ | ||
| ymd | | ||
ymd := self date yyyymmdd. | ||
ymd , self separatorString , aStringWithExtension ] | ||
] |
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
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 |
---|---|---|
@@ -1,6 +1,64 @@ | ||
Class { | ||
#name : 'MDFileNamer', | ||
#superclass : 'Object', | ||
#instVars : [ | ||
'separatorString', | ||
'defaultEmptyName' | ||
], | ||
#category : 'MicroEd', | ||
#package : 'MicroEd' | ||
} | ||
|
||
{ #category : 'naming' } | ||
MDFileNamer >> addExtensionIfNeeded: aString [ | ||
|
||
aString asFileReference extension isEmpty | ||
ifTrue: [ ^ aString, '.md' ]. | ||
^ aString | ||
|
||
] | ||
|
||
{ #category : 'accessing' } | ||
MDFileNamer >> defaultEmptyName [ | ||
|
||
^ defaultEmptyName | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MDFileNamer >> defaultEmptyName: aString [ | ||
"we may turn it into a sharedVariable to be able to avoid to specify it each time" | ||
|
||
defaultEmptyName := aString | ||
] | ||
|
||
{ #category : 'initialization' } | ||
MDFileNamer >> initialize [ | ||
|
||
super initialize. | ||
defaultEmptyName := 'unnamed.md'. | ||
separatorString := '_' | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
MDFileNamer >> newName [ | ||
^ self defaultEmptyName | ||
] | ||
|
||
{ #category : 'naming' } | ||
MDFileNamer >> newNameBasedOn: aString [ | ||
"Answer a String representing the receiver's file name" | ||
|
||
^ self addExtensionIfNeeded: aString | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MDFileNamer >> separatorString [ | ||
|
||
^ separatorString | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MDFileNamer >> separatorString: aString [ | ||
|
||
separatorString :=aString | ||
] |
This file was deleted.
Oops, something went wrong.