Skip to content

Commit

Permalink
Fixed the parent child bug and added many tests
Browse files Browse the repository at this point in the history
Monospace logic could be simplified but it needs to fix all visitors
  • Loading branch information
Ducasse committed May 21, 2024
1 parent 2c219e1 commit e1f1597
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,63 @@ MicParentChildrenCheckerTest >> testDocumentWithConfusedKids [
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [

| checker |
self skip.
checker := MicParentChildrenChecker new.
checker check: self document.
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedAnnotation [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '{!citation|name=Duca99a!}').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedFormat [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '**Bold**').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedInlineCode [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '`hello`').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedInput [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '<!inputFile|path=Chapters/bloc/element.md!>').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedLink [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: 'a link: [http://pharo.org](http://pharo.org)').
self assert: checker isOk.
self assert: checker orphanList isEmpty

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [

Expand Down
50 changes: 0 additions & 50 deletions src/Microdown/MicDocumentListBlock.class.st

This file was deleted.

7 changes: 7 additions & 0 deletions src/Microdown/MicEvaluatedBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ MicEvaluatedBlock >> children: anObject [
children := anObject
]

{ #category : 'visiting' }
MicEvaluatedBlock >> closeMe [

super closeMe.
self children do: [ :each | each basicParent: self ].
]

{ #category : 'printing' }
MicEvaluatedBlock >> plainText [
^ ( self children collect: [:each | each plainText ] ) joinUsing: ' '
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineBlockWithUrl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ MicInlineBlockWithUrl >> closeMe [
"the link url - ![alt text](url) - url is allowed to have title in quotes
(url ""title"") "

| split title|
| split title |
split := url splitOnFirst: Character space.
self reference: (MicResourceReference fromUri: split first).
title := (split second ifNil: [ '' ])
Expand Down
7 changes: 7 additions & 0 deletions src/Microdown/MicLinkBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ MicLinkBlock >> accept: aVisitor [
^ aVisitor visitLink: self
]

{ #category : 'visiting' }
MicLinkBlock >> closeMe [

super closeMe.
self children do: [ :each | each basicParent: self ].
]

{ #category : 'printing' }
MicLinkBlock >> plainText [
^ '[', ((self children collect: [:each | each plainText]) joinUsing: ' '), '](', url ,')'
Expand Down
24 changes: 21 additions & 3 deletions src/Microdown/MicMonospaceFormatBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ I represent a monospaced text section. I'm delimited using `\`` as in `\`monospa
Class {
#name : 'MicMonospaceFormatBlock',
#superclass : 'MicUnEvaluatedBlock',
#instVars : [
'children'
],
#category : 'Microdown-Model',
#package : 'Microdown',
#tag : 'Model'
Expand Down Expand Up @@ -33,14 +36,29 @@ MicMonospaceFormatBlock >> accept: aVisitor [

{ #category : 'accessing' }
MicMonospaceFormatBlock >> children [
"should be deprecated"

^ Array with: (MicTextBlock new bodyString: self bodyString)
^ children
]

{ #category : 'accessing' }
MicMonospaceFormatBlock >> children: aCollection [

children := aCollection
]

{ #category : 'accessing' }
MicMonospaceFormatBlock >> closeMe [
"Please note that in the children we will only store text. So this could be all removed
but at the cost of updating all the visitor that expect that the treatment on MicTextBlock will be done.
so for now to make sure that the tree is well formed we just store a text bloc and set correctly its parent. Just returning the text via children was not super nice and recipe to disaster since different nodes where returned at each invocation. "

super closeMe.
self children: (Array with: (MicTextBlock new bodyString: self bodyString)).
self children do: [ :each | each basicParent: self ].
]

{ #category : 'accessing' }
MicMonospaceFormatBlock >> text [
"should be deprecated "

^ self bodyString
]

0 comments on commit e1f1597

Please sign in to comment.