Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new version of the parent child checker #730

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading