Skip to content

Commit

Permalink
bodyString users left over
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Mar 23, 2024
1 parent b467977 commit 4dd41c6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 99 deletions.
189 changes: 104 additions & 85 deletions src/Microdown-Transformer-Tests/MicFileIncluderTest.class.st
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Class {
#name : #MicFileIncluderTest,
#superclass : #TestCase,
#name : 'MicFileIncluderTest',
#superclass : 'TestCase',
#instVars : [
'filesystem',
'includer',
'builder'
],
#category : #'Microdown-Transformer-Tests'
#category : 'Microdown-Transformer-Tests',
#package : 'Microdown-Transformer-Tests'
}

{ #category : #running }
{ #category : 'running' }
MicFileIncluderTest >> generateFilesystemExample [

| file |
Expand All @@ -31,7 +32,7 @@ Pharo is **cool**
' ]
]

{ #category : #running }
{ #category : 'running' }
MicFileIncluderTest >> setUp [
super setUp.
filesystem := FileSystem memory.
Expand All @@ -43,7 +44,7 @@ MicFileIncluderTest >> setUp [

]

{ #category : #'tests - simple' }
{ #category : 'tests - simple' }
MicFileIncluderTest >> testBeforeIncludingTheInputFile [

| root file reference |
Expand All @@ -61,7 +62,7 @@ MicFileIncluderTest >> testBeforeIncludingTheInputFile [

]

{ #category : #'tests - simple' }
{ #category : 'tests - simple' }
MicFileIncluderTest >> testGenerateFilesystemIsGood [

self assert: (filesystem workingDirectory / 'anExample1.md') contents equals: '# Foo
Expand All @@ -81,156 +82,174 @@ Pharo is **cool**
'
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testHandleNestedFileResolution [

| root file reference |
(filesystem workingDirectory / 'Chapters') createDirectory.
(filesystem workingDirectory / 'Chapters' / 'SUnit') createDirectory.

file := filesystem workingDirectory / 'Chapters' / 'SUnit.md'.
file writeStreamDo: [ :stream |
file writeStreamDo: [ :stream |
builder
setStream: stream;
setStream: stream;
inputfile: 'SUnit/anExample1.md' ].

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'anExample1.md'.
file writeStreamDo: [ :stream |

file := filesystem workingDirectory / 'Chapters' / 'SUnit'
/ 'anExample1.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
header: [builder text: 'Foo'] withLevel: 1;
setStream: stream;
header: [ builder text: 'Foo' ] withLevel: 1;
inputfile: 'anExample2.md' ].

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'anExample2.md'.
file writeStreamDo: [ :stream |

file := filesystem workingDirectory / 'Chapters' / 'SUnit'
/ 'anExample2.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
header: [builder text: 'Example2'] withLevel: 1 ].

reference := (MicResourceReference fromUri: 'file:///Chapters/SUnit.md') filesystem: filesystem.

setStream: stream;
header: [ builder text: 'Example2' ] withLevel: 1 ].

reference := (MicResourceReference fromUri:
'file:///Chapters/SUnit.md') filesystem: filesystem.

includer topFile: reference fileReference parent.
includer visit: (root := reference loadMicrodown).

self assert: root children first class equals: MicHeaderBlock.
self assert: root children first children first bodystring equals: 'Foo'.

self assert: root children second class equals: MicHeaderBlock.
self assert: root children second children first bodystring equals: 'Example2'.


self assert: root children first class equals: MicHeaderBlock.
self
assert: root children first children first bodyString
equals: 'Foo'.

self assert: root children second class equals: MicHeaderBlock.
self
assert: root children second children first bodyString
equals: 'Example2'
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testHandleNestedFileResolutionOnDifferentLevel [

| root file reference |
(filesystem workingDirectory / 'Chapters') createDirectory.
(filesystem workingDirectory / 'Chapters' / 'SUnit') createDirectory.
(filesystem workingDirectory / 'Chapters' / 'SUnit' / 'Sub') createDirectory.

(filesystem workingDirectory / 'Chapters' / 'SUnit' / 'Sub')
createDirectory.

file := filesystem workingDirectory / 'Chapters' / 'SUnit.md'.
file writeStreamDo: [ :stream |
file writeStreamDo: [ :stream |
builder
setStream: stream;
setStream: stream;
inputfile: 'SUnit/anExample1.md' ].

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'anExample1.md'.
file writeStreamDo: [ :stream |

file := filesystem workingDirectory / 'Chapters' / 'SUnit'
/ 'anExample1.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
header: [builder text: 'Foo'] withLevel: 1;
setStream: stream;
header: [ builder text: 'Foo' ] withLevel: 1;
inputfile: 'Sub/anExample2.md' ].

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'Sub' / 'anExample2.md'.
file writeStreamDo: [ :stream |

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'Sub'
/ 'anExample2.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
header: [builder text: 'Example2'] withLevel: 1 ].

reference := (MicResourceReference fromUri: 'file:///Chapters/SUnit.md') filesystem: filesystem.

setStream: stream;
header: [ builder text: 'Example2' ] withLevel: 1 ].

reference := (MicResourceReference fromUri:
'file:///Chapters/SUnit.md') filesystem: filesystem.

includer topFile: reference fileReference parent.
includer visit: (root := reference loadMicrodown).

self assert: root children first class equals: MicHeaderBlock.
self assert: root children first children first bodystring equals: 'Foo'.

self assert: root children second class equals: MicHeaderBlock.
self assert: root children second children first bodystring equals: 'Example2'.


self assert: root children first class equals: MicHeaderBlock.
self
assert: root children first children first bodyString
equals: 'Foo'.

self assert: root children second class equals: MicHeaderBlock.
self
assert: root children second children first bodyString
equals: 'Example2'
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testIncluderIncludesInputFileFromTheSameLevel [

| root file reference |
(filesystem workingDirectory / 'Chapters') createDirectory.
(filesystem workingDirectory / 'Chapters' / 'SUnit') createDirectory.

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'anExample1.md'.
file writeStreamDo: [ :stream |

file := filesystem workingDirectory / 'Chapters' / 'SUnit'
/ 'anExample1.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
setStream: stream;
header: [ builder text: 'Foo' ] withLevel: 1;
text: 'Pharo is cool';
codeblock: 'This is a code'].

file := filesystem workingDirectory / 'Chapters' / 'SUnit' / 'SUnit.md'.
file writeStreamDo: [ :stream |
codeblock: 'This is a code' ].

file := filesystem workingDirectory / 'Chapters' / 'SUnit'
/ 'SUnit.md'.
file writeStreamDo: [ :stream |
builder
setStream: stream;
setStream: stream;
inputfile: 'anExample1.md' ].

reference := (MicResourceReference fromUri: 'file:///Chapters/SUnit/SUnit.md') filesystem: filesystem.

reference := (MicResourceReference fromUri:
'file:///Chapters/SUnit/SUnit.md') filesystem:
filesystem.
root := reference loadMicrodown.

self assert: root children first class equals: MicInputfileBlock.
self assert: (root children first path isKindOf: MicResourceReference).
self assert:
(root children first path isKindOf: MicResourceReference).

includer visit: root.

self assert: root children first class equals: MicHeaderBlock.
self assert: root children first children first bodystring equals: 'Foo'.
self
assert: root children first children first bodyString
equals: 'Foo'.
self assert: root children second class equals: MicParagraphBlock.
self assert: root children third class equals: MicCodeBlock.



self assert: root children third class equals: MicCodeBlock
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testIncluderIncludesInputFilesWithinTheSameParagraph [
"As a general remark I do not like that the input can produce document that are not correct from a parser point of view. For example we should have a paragraph containing an header and this is what the transformation of the includer is doing."
| root file reference |

| root file reference |
file := filesystem workingDirectory / 'test.md'.
file writeStreamDo: [ :stream |
file writeStreamDo: [ :stream |
builder
setStream: stream;
setStream: stream;
inputfile: 'anExample1.md';
inputfile: 'anExample2.md' ].
reference := (MicResourceReference fromUri: 'file:///test.md') filesystem: filesystem.
reference := (MicResourceReference fromUri: 'file:///test.md')
filesystem: filesystem.
root := reference loadMicrodown.
includer visit: root.

self assert: root children first class equals: MicHeaderBlock.
self assert: root children first children first bodystring equals: 'Foo'.
self
assert: root children first children first bodyString
equals: 'Foo'.
self assert: root children first level equals: 1.
self assert: root children second class equals: MicParagraphBlock.
self assert: root children third class equals: MicCodeBlock.

self assert: root children fourth class equals: MicHeaderBlock.
self assert: root children fourth children first bodystring equals: 'Bar'.
self
assert: root children fourth children first bodyString
equals: 'Bar'.
self assert: root children fourth level equals: 2.
self assert: root children fifth class equals: MicParagraphBlock.
self assert: root children sixth class equals: MicCodeBlock
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testIncluderJustReturnInputFileBlockWhenIncludedFileDoesNotExist [

| root file reference |
Expand All @@ -249,7 +268,7 @@ MicFileIncluderTest >> testIncluderJustReturnInputFileBlockWhenIncludedFileDoesN
self assert: root children first class equals: MicInputfileBlock.
]

{ #category : #tests }
{ #category : 'tests' }
MicFileIncluderTest >> testMicFileInclusionTransformMicInputFiles [

| root file reference |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
I'm a silly `MicNodeTransformer`: I delete code block and replace paragraph by text.
"
Class {
#name : #MicNodeTransformerCodeDeleterMock,
#superclass : #MicNodeTransformer,
#category : #'Microdown-Transformer-Tests'
#name : 'MicNodeTransformerCodeDeleterMock',
#superclass : 'MicNodeTransformer',
#category : 'Microdown-Transformer-Tests',
#package : 'Microdown-Transformer-Tests'
}

{ #category : #visiting }
{ #category : 'visiting' }
MicNodeTransformerCodeDeleterMock >> visitCode: aCode [

self delete
]

{ #category : #visiting }
{ #category : 'visiting' }
MicNodeTransformerCodeDeleterMock >> visitParagraph: aParagraph [

self replaceCurrentNodeBy: { (MicTextBlock new bodystring: 'test') }
self replaceCurrentNodeBy: { (MicTextBlock new bodyString: 'test') }
]
15 changes: 8 additions & 7 deletions src/Microdown-Transformer-Tests/MicNodeTransformerTest.class.st
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
Class {
#name : #MicNodeTransformerTest,
#superclass : #TestCase,
#name : 'MicNodeTransformerTest',
#superclass : 'TestCase',
#instVars : [
'transformer'
],
#category : #'Microdown-Transformer-Tests'
#category : 'Microdown-Transformer-Tests',
#package : 'Microdown-Transformer-Tests'
}

{ #category : #running }
{ #category : 'running' }
MicNodeTransformerTest >> setUp [
super setUp.
transformer := MicNodeTransformerCodeDeleterMock new

]

{ #category : #tests }
{ #category : 'tests' }
MicNodeTransformerTest >> testDeleteNode [

| root |
Expand All @@ -26,13 +27,13 @@ this is a paragraph
self assert: root children size equals: 0
]

{ #category : #tests }
{ #category : 'tests' }
MicNodeTransformerTest >> testReplaceNodeByAnotherNode [

| root |
root := Microdown parse: 'this is a paragraph'.
self assert: root children first class equals: MicParagraphBlock.
transformer visit: root.
self assert: root children first class equals: MicTextBlock.
self assert: root children first bodystring equals: 'test'
self assert: root children first bodyString equals: 'test'
]
2 changes: 1 addition & 1 deletion src/Microdown-Transformer-Tests/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Microdown-Transformer-Tests' }
Package { #name : 'Microdown-Transformer-Tests' }

0 comments on commit 4dd41c6

Please sign in to comment.