forked from pillar-markup/Microdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pillar-markup#730 from Ducasse/dev
new version of the parent child checker
- Loading branch information
Showing
4 changed files
with
118 additions
and
124 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Microdown-ParentChildrenChecker/MicParentChildrenChecker.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Class { | ||
#name : 'MicParentChildrenChecker', | ||
#superclass : 'Object', | ||
#instVars : [ | ||
'orphanList', | ||
'confusedKids' | ||
], | ||
#category : 'Microdown-ParentChildrenChecker', | ||
#package : 'Microdown-ParentChildrenChecker' | ||
} | ||
|
||
{ #category : 'visiting main API' } | ||
MicParentChildrenChecker >> check: anElement [ | ||
"Check if the parent of the element correctly includes this element as a child" | ||
|
||
anElement parent | ||
ifNil: [ | ||
anElement class = MicRootBlock | ||
ifFalse: [ orphanList add: anElement ] | ||
ifTrue: [ anElement children do: [ :each | self check: each ] ] ] | ||
ifNotNil: [ :p | "We cannot identify bad parent that are refered by child not in the children | ||
list, because by construction the algo only considers the children of an element). | ||
(p children includes: anElement) ifFalse: [ self addParent: p ]." | ||
p children do: [ :child | | ||
child parent = p ifFalse: [ confusedKids add: child ] ]. | ||
|
||
anElement children do: [ :each | self check: each ] ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MicParentChildrenChecker >> confusedKids [ | ||
|
||
^ confusedKids | ||
] | ||
|
||
{ #category : 'visiting main API' } | ||
MicParentChildrenChecker >> initialize [ | ||
|
||
super initialize. | ||
orphanList := OrderedCollection new. | ||
confusedKids := OrderedCollection new | ||
] | ||
|
||
{ #category : 'testing' } | ||
MicParentChildrenChecker >> isOk [ | ||
|
||
^ confusedKids isEmpty and: | ||
(orphanList isEmpty and: [ confusedKids isEmpty ]) | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MicParentChildrenChecker >> orphanList [ | ||
^orphanList | ||
] |
64 changes: 64 additions & 0 deletions
64
src/Microdown-ParentChildrenChecker/MicParentChildrenCheckerTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Class { | ||
#name : 'MicParentChildrenCheckerTest', | ||
#superclass : 'TestCase', | ||
#category : 'Microdown-ParentChildrenChecker', | ||
#package : 'Microdown-ParentChildrenChecker' | ||
} | ||
|
||
{ #category : 'tests' } | ||
MicParentChildrenCheckerTest >> document [ | ||
^ Microdown parse: '#Microdown is quite cool | ||
Here is some code | ||
```language=Pharo&caption=Beautiful&anchor=Fig1 | ||
1000 factorial / 999 factorial | ||
``` | ||
Here is a figure and a link: [http://pharo.org](http://pharo.org). | ||
![Pharologo](https://files.pharo.org/media/logo/logo.png size=80&anchor=figLogo.) | ||
Here is a list: | ||
- item 1 | ||
1. sub item 1 | ||
3. sub item 2 | ||
- item 2 | ||
**Bold**, _italic_, `monospace` | ||
In Pharo, Microdown supports hyperlinks to: | ||
- classes e.g., `Point`, | ||
- methodes e.g., `Point class`, `Point>>#setX:setY:`, and | ||
- packages e.g., `#''Microdown-Tests''` (for packages). | ||
You can edit this file clicking on `ClySyntaxHelpMorph>>#rawMicrodownSyntax`.'. | ||
|
||
] | ||
|
||
{ #category : 'tests' } | ||
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [ | ||
|
||
| checker | | ||
checker := MicParentChildrenChecker new. | ||
checker check: self document. | ||
self assert: checker isOk | ||
] | ||
|
||
{ #category : 'tests' } | ||
MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [ | ||
|
||
| brokenDocument visitor orphan | | ||
visitor := MicParentChildrenChecker new. | ||
brokenDocument := Microdown parse: '# Microdown is quite cool'. | ||
orphan := brokenDocument children first children first. | ||
orphan basicParent: nil. | ||
self assert: orphan parent isNil. | ||
|
||
visitor check: brokenDocument. | ||
|
||
self deny: visitor isOk | ||
] |
68 changes: 0 additions & 68 deletions
68
src/Microdown-ParentChildrenChecker/ParentChildrenChecker.class.st
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
src/Microdown-ParentChildrenChecker/ParentChildrenCheckerTest.class.st
This file was deleted.
Oops, something went wrong.