Skip to content

Commit

Permalink
Merge pull request #730 from Ducasse/dev
Browse files Browse the repository at this point in the history
new version of the parent child checker
  • Loading branch information
Ducasse authored May 3, 2024
2 parents a4e5d5a + d1af987 commit aae97c4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 124 deletions.
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
]
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 src/Microdown-ParentChildrenChecker/ParentChildrenChecker.class.st

This file was deleted.

This file was deleted.

0 comments on commit aae97c4

Please sign in to comment.