Skip to content

Commit

Permalink
Merge pull request #745 from moufort/webDeveloppemment
Browse files Browse the repository at this point in the history
Add test to Microdown blog
  • Loading branch information
Ducasse authored May 22, 2024
2 parents e88a51f + 8469e4f commit f9c1edc
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 24 deletions.
171 changes: 171 additions & 0 deletions src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
Class {
#name : 'MicBlogCreatorTest',
#superclass : 'TestCase',
#instVars : [
'fileSystem'
],
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> fileContent1 [

^ '{
"date" : "8 January 2019"
}
# A Cool Story
Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more!
'

]

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> fileContent2 [

^ '{
"date" : "22 January 2019"
}
# Pharo is cool
If you are either a beginner or an expert in object-oriented programming, _this MOOC_ will change the way you program with objects: come and learn or rediscover _object-oriented programming_ with Pharo!
Pharo is a pure _object-oriented programming language_ in the tradition of Smalltalk. It offers a unique developing experience in constant interaction with live objects. Pharo is elegant, fun to use and very powerful. It is very easy to learn and enables to understand advanced concept in a natural way. When programming in Pharo, you are immersed in a world of live objects. You have immediate feedback at any moment of your development on objects representing web applications, code itself, graphics, network. More…
'


]

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> fileContent3 [

^ '{
"date" : "29 January 2018"
}
# Mooc Pharo
Welcome to the Pharo Mooc (a set of videos, exercises, challenges, and miniprojects).
The Pharo Mooc is fully dubbed in french and english. It comes with subtitles in Japanese, english, french and spanish. This web site contains all the material of this Mooc in free access.
In addition, in average every 18 months the Mooc is proposed and run on the France Université Numérique platform (Even if the platform is french the mooc is run in both languages).
When you participate to the mooc you get access to the quizz and the credit validation.
'
]

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> generateArchitecture [

| fileSystem ref1 ref2 ref3 |
fileSystem := FileSystem memory.
fileSystem createDirectory: '/html'.
fileSystem createDirectory: '/source'.

ref1 := fileSystem workingDirectory / 'source/anExample1.md'.
ref1 writeStreamDo: [ :stream | stream nextPutAll: self fileContent1 ].

ref2 := fileSystem workingDirectory / 'source/anExample2.md'.
ref2 writeStreamDo: [ :stream | stream nextPutAll: self fileContent2 ].

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

^ fileSystem
]

{ #category : 'as yet unclassified' }
MicBlogCreatorTest >> listOfFile [

^ (fileSystem / 'source') allChildren select: [ :each | each isFile ]
]

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

"Put here a common initialization logic for tests"
fileSystem := self generateArchitecture
]

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

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

self assert: fileList 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 ].

self assert: allFile size equals: 6
]

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

| root blog |
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
]

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

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

allFileParse := self listOfFile collect: [ :each |
Microdown parse: each asFileReference contents ].

root := summarizer
group: allFileParse
byDate: (Month year: 2019 month: 'January').
root := summarizer summarize: root.

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

self assert: (fileSystem / 'html/2019/January/index.html') exists
]

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

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

self assert: (fileSystem / 'html/index.html') exists
]
15 changes: 15 additions & 0 deletions src/Microdown-Blog-Tests/MicDocumentTransformerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Class {
#name : 'MicDocumentTransformerTest',
#superclass : 'TestCase',
#category : 'Microdown-Blog-Tests',
#package : 'Microdown-Blog-Tests'
}

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

| link |

link := MicInlineParser parse: '[Pharo is cool](Test)'.
self assert: (MicDocumentTransformer makeALink: 'Pharo is cool' to: 'Test' ) equals: link.
]
2 changes: 1 addition & 1 deletion src/Microdown-Blog-Tests/MicSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ MicSummarizerTest >> testGroupByDate [
summary := self createListOfMicRootBlock.
group := micSummarizer
group: summary
byDate: (Date newDay: 1 month: 'January' year: 2019).
byDate: (Date newDay: 1 month: 'January' year: 2019) month.

self assert: group size equals: 2
]
Expand Down
45 changes: 25 additions & 20 deletions src/Microdown-Blog/MicBlogCreator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ MicBlogCreator class >> createFrom: source to: target [
| tmp1 |
tmp1 := self new.
tmp1
sourceDirectory: source;
targetDirectory: target.
tmp1 createAllHtmlFile.
sourceDirectory: FileReference / source;
targetDirectory: FileReference / target.
tmp1 createAllHtmlFile
]

{ #category : 'as yet unclassified' }
MicBlogCreator >> collectAllFile [

^ (FileReference / sourceDirectory) allChildren select: [ :each | each isFile ]
^ sourceDirectory allChildren select: [ :each |
each isFile ]
]

{ #category : 'rendering' }
Expand All @@ -37,7 +38,7 @@ MicBlogCreator >> createAllHtmlFile [
allFileParse do: [ :each | self createHtmlFile: each ].

sum := MicSummarizer new.
sum targetDirectory: targetDirectory .
sum targetDirectory: targetDirectory.

self createHtmlSummarize: (sum summarizeFile: allFile).

Expand All @@ -51,24 +52,24 @@ MicBlogCreator >> createAllHtmlFile [
{ #category : 'rendering' }
MicBlogCreator >> createHtmlFile: aMicRoot [

| a q date header |

| a q date header fileRef|
self rootAssembly: aMicRoot.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

date := (aMicRoot children at: 1) body at: #date.
date := date asDate.
header := MicSingleSummarizer new firstHeaderBlockOf: aMicRoot.

fileRef := targetDirectory copyWithPath: (targetDirectory fullPath asUrl path , '/' , date year asString
, '/' , date monthName , '/' , date day asString , '/').

q := MicHTMLDocument new.
q configuration: a configuration.
q configuration document: q.
q
setCharSetUTF8;
destinationPath:
targetDirectory , '\' , date year asString , '\' , date monthName
, '\' , date day asString , '\'.
destinationPath: fileRef .
^ q
fileName: header text , '.html';
writeDocument: a contents;
Expand All @@ -78,19 +79,21 @@ MicBlogCreator >> createHtmlFile: aMicRoot [
{ #category : 'rendering' }
MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aDate [

| a q |
| a q fileRef |
self rootAssembly: aMicRoot.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

fileRef := targetDirectory copyWithPath:
targetDirectory fullPath asUrl path , '/'
, aDate year asString , '/' , aDate monthName , '/'.

q := MicHTMLDocument new.
q configuration: a configuration.
q configuration document: q.
q
setCharSetUTF8;
destinationPath:
targetDirectory , '\' , aDate year asString , '\' , aDate monthName
, '\'.
destinationPath: fileRef.
^ q
writeDocument: a contents;
contents
Expand All @@ -99,18 +102,20 @@ MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aDate [
{ #category : 'rendering' }
MicBlogCreator >> createHtmlSummarize: aMicRoot [

| a q |

| a q fileRef |
self rootAssembly: aMicRoot.

a := (MicHTMLVisitor new visit: aMicRoot) at: 1.

fileRef := targetDirectory copyWithPath:
targetDirectory fullPath asUrl path.

q := MicHTMLDocument new.
q configuration: a configuration.
q configuration document: q.
q
setCharSetUTF8;
destinationPath: targetDirectory.
destinationPath: fileRef.
^ q
writeDocument: a contents;
contents
Expand Down
4 changes: 3 additions & 1 deletion src/Microdown-Blog/MicDocumentTransformer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Class {
{ #category : 'as yet unclassified' }
MicDocumentTransformer class >> makeALink: aText to: aLink [

^ MicInlineParser parse: '[' , aText, '](' , aLink , ')'
^ MicInlineParser parse:
'[' , aText printString asString , ']('
, aLink printString asString , ')'
]

{ #category : 'accessing' }
Expand Down
4 changes: 2 additions & 2 deletions src/Microdown-Blog/MicSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Class {
}

{ #category : 'grouping' }
MicSummarizer >> group: aListOfSingleSummarizer byDate: aDate [
MicSummarizer >> group: aListOfSingleSummarizer byDate: aMonth [

| metadataDate |
^ aListOfSingleSummarizer select: [ :each |
metadataDate := (each children at: 1) body at: #date.
metadataDate asDate month = aDate month]
metadataDate asDate month = aMonth ]
]

{ #category : 'initialization' }
Expand Down

0 comments on commit f9c1edc

Please sign in to comment.