Skip to content

Commit

Permalink
Session with Yasser
Browse files Browse the repository at this point in the history
- rename inptuFileFinder into InputFileExpressionCollector
- Add tests to InputFileExpressionCollectorTest
- add comment to MicFileIncluder
- fix little glitches in MicBookTesterVisitor
  • Loading branch information
Ducasse committed Jun 27, 2024
1 parent bc82c06 commit 060e04d
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Class {
#name : 'MicInputFileExpressionCollectorTest',
#superclass : 'TestCase',
#instVars : [
'fs',
'dir'
],
#category : 'Microdown-BookTester-Tests',
#package : 'Microdown-BookTester-Tests'
}

{ #category : 'accessing' }
MicInputFileExpressionCollectorTest >> fileSystem [

^ FileSystem memory
]

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

super setUp.
fs := self fileSystem.
dir := (fs / 'myDirectory') asFileReference.
dir ensureCreateDirectory
]

{ #category : 'tests' }
MicInputFileExpressionCollectorTest >> testAllInputInASingleFile [

| doc visitor |
doc := Microdown parse: '# Section 1

<!inputFile|path=Chapters/Intro.md!>
%Reviewed by stef - anchor

# All Spec in One Example

<!inputFile|path=Chapters/FirstContact.md!>

<!inputFile|path=Chapters/CaseStudyOne.md!>
%Reviewed by stef - anchor

# Spec Essentials

<!inputFile|path=InANutshell.md!>

'.
visitor := MicInputFileExpressionCollector new.
doc accept: visitor.
self
assert: (visitor allFiles collect: [:each | each path relativePath ] )
equals: OrderedCollection <- #('Chapters/Intro.md' 'Chapters/FirstContact.md' 'Chapters/CaseStudyOne.md' 'InANutshell.md')



]

{ #category : 'tests' }
MicInputFileExpressionCollectorTest >> testAllInputsTwoSingleFile [

| doc visitor doc2 |
doc := Microdown parse: '# Section 1

<!inputFile|path=Chapters/Intro.md!>
%Reviewed by stef - anchor

# All Spec in One Example

<!inputFile|path=Chapters/FirstContact.md!>

<!inputFile|path=Chapters/CaseStudyOne.md!>
%Reviewed by stef - anchor

# Spec Essentials

<!inputFile|path=InANutshell.md!>

'.

doc2 := Microdown parse: '# Section 2


<!inputFile|path=Chapters/FirstContact2.md!>


'.
visitor := MicInputFileExpressionCollector new.
doc accept: visitor.
doc2 accept: visitor.
self
assert: (visitor allFiles collect: [:each | each path relativePath ] )
equals: OrderedCollection <- #('Chapters/Intro.md' 'Chapters/FirstContact.md' 'Chapters/CaseStudyOne.md' 'InANutshell.md' 'Chapters/FirstContact2.md')



]
48 changes: 23 additions & 25 deletions src/Microdown-BookTester/MicBookTesterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ MicBookTesterVisitor >> allTestResults: anObject [
{ #category : 'visiting' }
MicBookTesterVisitor >> checkAssociation: aCodeBlockObject [
"Asserts the association created in any codeBlock "
|association|
association := (self class compiler evaluate: aCodeBlockObject text) .
^ (association key = association value )

| association |
association := self class compiler evaluate: aCodeBlockObject text.
^ association key = association value
]

{ #category : 'visiting' }
MicBookTesterVisitor >> excuteAndReportExample: aCodeBlockObject [
"aCodeBlockObject is an instance of The MicrodownTestResult"
MicBookTesterVisitor >> executeAndReportIn: aCodeBlockObject [
"aCodeBlockObject is an instance of The MicrodownTestResult"

| isCorrect |
isCorrect := false .
[ isCorrect := self checkAssociation: aCodeBlockObject ]
on: Exception
do: [ :exception | aCodeBlockObject explanation: exception asString ] .
aCodeBlockObject status: isCorrect .
isCorrect
ifTrue: [ aCodeBlockObject explanation: 'Test passed' ]
isCorrect := false.
[ isCorrect := self checkAssociation: aCodeBlockObject ]
on: Exception
do: [ :exception | aCodeBlockObject explanation: exception asString ].
aCodeBlockObject status: isCorrect.
isCorrect ifTrue: [ aCodeBlockObject explanation: 'Test passed' ]
]

{ #category : 'visiting' }
Expand Down Expand Up @@ -84,22 +84,20 @@ MicBookTesterVisitor >> validTests [
]

{ #category : 'visiting' }
MicBookTesterVisitor >> visitCode: aCodeBlock [
"Creates an instance of PRBookTestResult with parameters depending of the type of the codeblock.
MicBookTesterVisitor >> visitCode: aCodeBlock [
"Creates an instance of PRBookTestResult with parameters depending of the type of the codeblock.
Here it is for an example and therefore uses the specialized exmple methods
textForTestcase
executeAndReportExample:
Note that there is no fragmentedText here, no need for it b/ecause the codeblock text contains the whole text and is the equivalent of Playground execution"
aCodeBlock isExample
ifFalse: [ ]
ifTrue: [
| result |

aCodeBlock isExample
ifTrue: [
| result |
result := MicBookTestResult new.
result text: aCodeBlock code.
allTestResults add: result .
self excuteAndReportExample: result.
aCodeBlock isExpectedFailure
ifTrue: [ result status: result status not]
]

allTestResults add: result.
self executeAndReportIn: result.
aCodeBlock isExpectedFailure ifTrue: [
result status: result status not ] ]
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"
I'm a simple visitor that collects file input nodes from a document.
"
Class {
#name : 'MicInputFileFinder',
#name : 'MicInputFileExpressionCollector',
#superclass : 'MicrodownVisitor',
#instVars : [
'allFiles'
Expand All @@ -9,19 +12,19 @@ Class {
}

{ #category : 'accessing' }
MicInputFileFinder >> allFiles [
MicInputFileExpressionCollector >> allFiles [
^ allFiles
]

{ #category : 'initialization' }
MicInputFileFinder >> initialize [
MicInputFileExpressionCollector >> initialize [

super initialize.
allFiles := OrderedCollection new.
]

{ #category : 'initialization' }
MicInputFileFinder >> visitInputFile: anInputFile [
MicInputFileExpressionCollector >> visitInputFile: anInputFile [

allFiles add: anInputFile
]
2 changes: 2 additions & 0 deletions src/Microdown-Transformer/MicElement.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ Extension { #name : 'MicElement' }
{ #category : '*Microdown-Transformer' }
MicElement >> inlineInputFiles [
"Assume all input has been resolved."
"The file includer is modifying the document on which it is acting."

MicFileIncluder new visit: self
]
28 changes: 18 additions & 10 deletions src/Microdown-Transformer/MicFileIncluder.class.st
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
"
I replace the inputFileBlock by the nodes of the file.
I replace the inputFileBlock (e.g., <!inputFile|path=Chapters/InANutshell/InANutshell.md!>) by the nodes of the file.
In particular I resolve paths to the correct places.
For example imagine that we have the file
For example imagine that we have the file `Books/Book1/index.md` containing

`Books/Book1/index.mic`
containing
`${inputfile&path=SUnit/SUnit.mic$`
and that `SUnit/SUnit.mic` contains a figure
```
...
<!inputfile|path=SUnit/SUnit.md!>
...

```

and that SUnit/SUnit.md contains a figure
such as
`![](figures/setUpTearDown.png)`
Such `figures/setUpTearDown.png` file should get its path being: `Books/Book1/SUnit/figures/setUpTearDown.png`

```
![](figures/setUpTearDown.png)

```

The figure should be inlined inside the index.md document.
In addition such figures/setUpTearDown.png file should get its path being: `Books/Book1/SUnit/figures/setUpTearDown.png`

Note that if the path does not exist the transformer does nothing.
"
Expand Down

0 comments on commit 060e04d

Please sign in to comment.