Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test and verification in Microdown-Blog #790

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,32 @@ MicBlogCreatorTest >> testSortSingleSummarizedDocuments [
assert: (listOfSummarizedDocuments at: 3) equals: summarized2
]

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

self assert: (fileSystem / 'source') hasChildren.
blog targetDirectory: fileSystem / 'source'.
self assert: (fileSystem / 'source') hasChildren not.
]

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

blog targetDirectory: fileSystem / 'html'.

self assert: blog targetDirectory equals: fileSystem / 'html'
]

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

"we use basename cause we can't pass the memory with a String"

blog targetDirectory: 'html'.

self assert: blog targetDirectory basename equals: (fileSystem / 'html') basename
]

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

Expand Down
38 changes: 38 additions & 0 deletions src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@ MicMonthListCreatorTest >> setUp [
monthListCreator root: MicFileTestResources new genericEmptyRootPath
]

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

| dateList january2019 january2018 listSummarizerTest|
listSummarizerTest := MicListSummarizerTest new.
listSummarizerTest setUp.
dateList := monthListCreator createListOfMonthListFromSummarized: listSummarizerTest createListOfMicRootBlock.

january2019 := Month year: 2019 month: 1.
january2018 := Month year: 2018 month: 1.

self assert: (dateList isKindOf: Set);
assert: dateList size equals: 2;
assert: (dateList includes: january2018);
assert: (dateList includes: january2019)
]

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

| singleSummarizer summarizedDocument dateList january2019 |

singleSummarizer := MicSingleSummarizer new.
singleSummarizer targetDirectory: '/html/' asFileReference;
root: MicFileTestResources new genericEmptyRootPath.

summarizedDocument := (singleSummarizer summarize:
((Microdown parse: ressources generateFilesystemExample1 contents)
fromFile: ressources generateFilesystemExample1)).
dateList := monthListCreator createListOfMonthListFromSummarized: { summarizedDocument copy. summarizedDocument copy. summarizedDocument copy }.

january2019 := Month year: 2019 month: 1.

self assert: (dateList isKindOf: Set);
assert: dateList size equals: 1;
assert: (dateList includes: january2019)
]

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

Expand Down
36 changes: 36 additions & 0 deletions src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,30 @@ MicSingleSummarizerTest >> testSummarizeFile [
self assert: (root isKindOf: MicRootBlock)
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithFromFile [

| root fromFile |
root := self createMicRootBlock.
fromFile := root fromFile.

micSingleSummarizer verifyFromFile: root.

self assert: root fromFile equals: fromFile
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithFromFileNil [

| root |
root := self createMicRootBlock.
root fromFile: nil.

micSingleSummarizer verifyFromFile: root.

self assert: root fromFile equals: ''
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithMetaDataAndWithDate [

Expand Down Expand Up @@ -237,6 +261,18 @@ MicSingleSummarizerTest >> testWithMetaDataButInvalidDate [
equals: micSingleSummarizer replacementDate
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithoutFromFile [

| root |
root := Microdown parse:
resources generateFilesystemExample1 contents.

micSingleSummarizer verifyFromFile: root.

self assert: root fromFile equals: ''
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithoutMetaData [

Expand Down
17 changes: 17 additions & 0 deletions src/Microdown-Blog/MicSingleSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ MicSingleSummarizer >> headerLink: aMicRootBlock [
| headerLink header fileReference |
headerLink := MicHeaderBlock new.
header := self firstHeaderBlockOf: aMicRootBlock.

self verifyFromFile: aMicRootBlock.

fileReference := (aMicRootBlock fromFile withoutExtension fullName
withoutPrefix: targetDirectory fullName) , '.html'.
Expand Down Expand Up @@ -131,3 +133,18 @@ MicSingleSummarizer >> summarizeFile: aFileReference [
root fromFile: aFileReference.
^ self summarize: root
]

{ #category : 'accessing' }
MicSingleSummarizer >> verifyFromFile: aMicRootBlock [

| newFromFile |

newFromFile := ''.

aMicRootBlock properties ifNotNil: [
aMicRootBlock properties ifNotEmpty: [
aMicRootBlock fromFile ifNotNil: [
newFromFile := aMicRootBlock fromFile ] ] ].

aMicRootBlock fromFile: newFromFile
]
Loading