Skip to content

Commit

Permalink
Cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed May 3, 2024
1 parent b31a218 commit d1af987
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
Class {
#name : 'MicParentChildrenChecker',
#superclass : 'MicrodownVisitor',
#superclass : 'Object',
#instVars : [
'orphanList',
'badReferencingParentList',
'confusedKids'
],
#category : 'Microdown-ParentChildrenChecker',
#package : 'Microdown-ParentChildrenChecker'
}

{ #category : 'visiting main API' }
MicParentChildrenChecker >> addChild: aChild [
orphanList add: aChild .
]

{ #category : 'visiting main API' }
MicParentChildrenChecker >> addParent: aParent [
badReferencingParentList add: aParent .
]

{ #category : 'testing' }
MicParentChildrenChecker >> badReferencingParentList [

^ badReferencingParentList
]
MicParentChildrenChecker >> check: anElement [
"Check if the parent of the element correctly includes this element as a child"

{ #category : 'visiting main API' }
MicParentChildrenChecker >> childrenList [
^ orphanList
]
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 ] ].

{ #category : 'visiting main API' }
MicParentChildrenChecker >> childrenList: anObject [
orphanList := anObject
anElement children do: [ :each | self check: each ] ]
]

{ #category : 'testing' }
{ #category : 'accessing' }
MicParentChildrenChecker >> confusedKids [

^ confusedKids
Expand All @@ -47,48 +38,17 @@ MicParentChildrenChecker >> initialize [

super initialize.
orphanList := OrderedCollection new.
badReferencingParentList := OrderedCollection new.
confusedKids := OrderedCollection new
]

{ #category : 'testing' }
MicParentChildrenChecker >> isOk [

^ badReferencingParentList isEmpty and:
( orphanList isEmpty and: [ confusedKids isEmpty ])
^ confusedKids isEmpty and:
(orphanList isEmpty and: [ confusedKids isEmpty ])
]

{ #category : 'testing' }
{ #category : 'accessing' }
MicParentChildrenChecker >> orphanList [
^orphanList
]

{ #category : 'visiting main API' }
MicParentChildrenChecker >> parentsList [
^ badReferencingParentList
]

{ #category : 'visiting main API' }
MicParentChildrenChecker >> parentsList: anObject [
badReferencingParentList := anObject
]

{ #category : 'visiting main API' }
MicParentChildrenChecker >> visit: 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 visit: 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 addChild: child ] ].

anElement children do: [ :each | self visit: each ] ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ You can edit this file clicking on `ClySyntaxHelpMorph>>#rawMicrodownSyntax`.'.
{ #category : 'tests' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [

| visitor |
visitor := MicParentChildrenChecker new.
self document accept: visitor.
self assert: visitor isOk.





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

{ #category : 'tests' }
Expand All @@ -63,7 +58,7 @@ MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [
orphan basicParent: nil.
self assert: orphan parent isNil.

visitor visit: brokenDocument.
visitor check: brokenDocument.

self deny: visitor isOk
]

0 comments on commit d1af987

Please sign in to comment.