Skip to content

Commit

Permalink
Merge pull request #748 from moufort/webDeveloppemment
Browse files Browse the repository at this point in the history
Refactoring and add Test in Microdown-Blog
  • Loading branch information
Ducasse authored May 23, 2024
2 parents de0a4ab + 7ed271e commit b901bb4
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 143 deletions.
68 changes: 36 additions & 32 deletions src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : 'MicBlogCreatorTest',
#superclass : 'TestCase',
#instVars : [
'fileSystem'
'fileSystem',
'blog'
],
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
Expand Down Expand Up @@ -61,7 +62,7 @@ When you participate to the mooc you get access to the quizz and the credit vali
{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> generateArchitecture [

| fileSystem ref1 ref2 ref3 |
| ref1 ref2 ref3 |
fileSystem := FileSystem memory.
fileSystem createDirectory: '/html'.
fileSystem createDirectory: '/source'.
Expand All @@ -74,8 +75,7 @@ MicBlogCreatorTest >> generateArchitecture [

ref3 := fileSystem workingDirectory / 'source/anExample3.md'.
ref3 writeStreamDo: [ :stream | stream nextPutAll: self fileContent3 ].

^ fileSystem

]

{ #category : 'as yet unclassified' }
Expand All @@ -86,56 +86,65 @@ MicBlogCreatorTest >> listOfFile [

{ #category : 'running' }
MicBlogCreatorTest >> setUp [

super setUp.

"Put here a common initialization logic for tests"
fileSystem := self generateArchitecture
self generateArchitecture.
blog := MicBlogCreator new.
blog
targetDirectory: fileSystem / 'html';
sourceDirectory: fileSystem / 'source'.
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCollectAllFile [
MicBlogCreatorTest >> testCollectAllMarkDownFile [

| blog fileList |
blog := MicBlogCreator new.
blog sourceDirectory: fileSystem workingDirectory / 'source'.
fileList := blog collectAllFile.
| fileList |

fileList := blog collectAllMarkDownFile.

self assert: fileList size equals: 3
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCopySourceDirectoryInTarget [

blog copySourceDirectoryInTarget.

self assert: (fileSystem / 'html') children size equals: 3
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCreateAllHtmlFile [

| blog allFile |
blog := MicBlogCreator new.
blog
targetDirectory: fileSystem / 'html';
sourceDirectory: fileSystem / 'source';
createAllHtmlFile.

allFile := (fileSystem / 'html') allChildren select: [ :each | each isFile ].
| allFile |

blog createAllHtmlFile.

allFile := (fileSystem / 'html') allChildren select: [ :each |
each isFile ].

self assert: allFile size equals: 6
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCreateHtmlFile [

| root blog |
| root |
root := Microdown parse:
(fileSystem / 'source/anExample1.md') readStream.
blog := MicBlogCreator new.
blog
targetDirectory: fileSystem / 'html';
createHtmlFile: root.

self assert: (fileSystem / 'html/2019/January/8/A Cool Story.html') exists
self assert:
(fileSystem / 'html/2019/January/8/A Cool Story.html') exists
]

{ #category : 'tests' }
MicBlogCreatorTest >> testCreateHtmlGroupFileAt [

| root blog summarizer allFileParse |
| root summarizer allFileParse |
summarizer := MicSummarizer new.
summarizer targetDirectory: 'html'.

Expand All @@ -147,9 +156,7 @@ MicBlogCreatorTest >> testCreateHtmlGroupFileAt [
byDate: (Month year: 2019 month: 'January').
root := summarizer summarize: root.

blog := MicBlogCreator new.
blog
targetDirectory: fileSystem / 'html';
blog
createHtmlGroupFile: root at: (Month year: 2019 month: 'January').

self assert: (fileSystem / 'html/2019/January/index.html') exists
Expand All @@ -158,14 +165,11 @@ MicBlogCreatorTest >> testCreateHtmlGroupFileAt [
{ #category : 'tests' }
MicBlogCreatorTest >> testCreateHtmlSummarize [

| root blog summarizer |
| root summarizer |
summarizer := MicSummarizer new.
summarizer targetDirectory: 'html'.
summarizer targetDirectory: 'html'.
root := summarizer summarizeFile: self listOfFile.
blog := MicBlogCreator new.
blog
targetDirectory: fileSystem / 'html';
createHtmlSummarize: root.
blog createHtmlSummarize: root.

self assert: (fileSystem / 'html/index.html') exists
]
28 changes: 26 additions & 2 deletions src/Microdown-Blog-Tests/MicDocumentTransformerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,31 @@ Class {
MicDocumentTransformerTest class >> testMakeALinkTo [

| link |

link := MicInlineParser parse: '[Pharo is cool](Test)'.
self assert: (MicDocumentTransformer makeALink: 'Pharo is cool' to: 'Test' ) equals: link.
self
assert:
(MicAbstractBlogCreator new makeALink: 'Pharo is cool' to: 'Test')
equals: link
]

{ #category : 'tests' }
MicDocumentTransformerTest >> testMakeALinkTo [

| link |
link := MicAbstractBlogCreator new makeALink: 'Pharo is cool' to: 'Test'.

self
assert: (link isKindOf: MicLinkBlock) equals: true;
assert: link plainText equals: '[Pharo is cool](Test)'
]

{ #category : 'tests' }
MicDocumentTransformerTest >> testMakeALinkToWithEmptyArguments [

| link |
link := MicAbstractBlogCreator new makeALink: '' to: ''.

self
assert: (link isKindOf: MicLinkBlock) equals: true;
assert: link plainText equals: '[Undefined](Undefined)'
]
37 changes: 37 additions & 0 deletions src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class {
#name : 'MicMonthListCreatorTest',
#superclass : 'TestCase',
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}

{ #category : 'tests' }
MicMonthListCreatorTest >> numberOfMonthSince2014 [

^ Date today year - 2014 * 12 + Date today month index
]

{ #category : 'tests' }
MicMonthListCreatorTest >> testGenerateDateListSince2014 [

| dateList |

dateList := MicMonthListCreator new generateDateListSince2014.

self assert: dateList size equals: (Date today year - 2014)*12 + Date today month index .
self assert: dateList first equals: (Date newDay: 1 month: 1 year: 2014) month .
self assert: dateList last equals: Date today month .
]

{ #category : 'tests' }
MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateTo [

| dateList |
dateList := MicMonthListCreator new
generateMicListBlockOfLinkDateTo: '/html'.

self assert: (dateList isKindOf: MicUnorderedListBlock).
self
assert: dateList children size
equals: self numberOfMonthSince2014.
]
35 changes: 35 additions & 0 deletions src/Microdown-Blog/MicAbstractBlogCreator.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Class {
#name : 'MicAbstractBlogCreator',
#superclass : 'Object',
#instVars : [
'targetDirectory'
],
#category : 'Microdown-Blog',
#package : 'Microdown-Blog'
}

{ #category : 'as yet unclassified' }
MicAbstractBlogCreator >> makeALink: aText to: aLink [

| text link |
(aText isNil or: aText isEmpty)
ifTrue: [ text := 'Undefined' ]
ifFalse: [ text := aText ].
(aLink isNil or: aLink isEmpty)
ifTrue: [ link := 'Undefined' ]
ifFalse: [ link := aLink ].

^ (MicInlineParser parse: '[' , text , '](' , link , ')') first
]

{ #category : 'accessing' }
MicAbstractBlogCreator >> targetDirectory [

^ targetDirectory
]

{ #category : 'accessing' }
MicAbstractBlogCreator >> targetDirectory: target [

targetDirectory := target
]
Loading

0 comments on commit b901bb4

Please sign in to comment.