Skip to content

Commit

Permalink
Merge pull request #816 from pillar-markup/enhExplanation
Browse files Browse the repository at this point in the history
Enh explanation
  • Loading branch information
Ducasse authored Aug 3, 2024
2 parents 86ac737 + e57bf11 commit 16716ae
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 73 deletions.
59 changes: 40 additions & 19 deletions src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ MicReferenceCheckerTest >> testDefAndReferToAMathEquationInFile [
self defEq1AndReferToEq1.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self assert: (visitor checkProject: defEq1AndReferToEq1).
visitor checkProject: defEq1AndReferToEq1.
self assert: visitor isOkay.
self assert: visitor results isEmpty
]

Expand All @@ -321,7 +322,8 @@ MicReferenceCheckerTest >> testDefFig1AndRefToAncS0UnknowAnchor [
self defFig1AndRefToAncS0.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self deny: (visitor checkProject: defFig1AndRefToAnsC0 ).
visitor checkProject: defFig1AndRefToAnsC0.
self deny: visitor isOkay.
self assert: visitor results first anchorLabel equals: 'ancS0'.
self
assert: visitor results first source
Expand All @@ -334,7 +336,8 @@ MicReferenceCheckerTest >> testDefFig1AndRefToAncUnkS0 [
| visitor |
self defFig1AndRefToAncUnkS0.
visitor := MicReferenceChecker new.
self deny: (visitor checkList: { defFig1AndRefToAncUnkS0 }).
visitor checkList: { defFig1AndRefToAncUnkS0 }.
self deny: visitor isOkay.
self assert: visitor results size equals: 1.
self assert: visitor results first anchorLabel equals: 'ancUnkS0'.
self assert: visitor results first source equals: '/defFig1AndRefToAncUnkS0.md'
Expand All @@ -347,7 +350,8 @@ MicReferenceCheckerTest >> testDefFig1AndReferToFig1 [
self defFig1AndRefFig1.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self assert: (visitor checkProject: defAndRefFig1).
visitor checkProject: defAndRefFig1.
self assert: visitor isOkay.
self assert: visitor results isEmpty
]

Expand All @@ -357,8 +361,8 @@ MicReferenceCheckerTest >> testDefFig1ReferToAFigureInFile [
| visitor |
self defFig1AndRefFig1.
visitor := MicReferenceChecker new.
self assert: (visitor checkList: { defAndRefFig1 }).
self assert: visitor results isEmpty
visitor checkList: { defAndRefFig1 }.
self assert: visitor isOkay.

]

Expand All @@ -369,7 +373,8 @@ MicReferenceCheckerTest >> testDefS1ButRefersToS0UnknownAnchor [
self fileDefAncS1UndAncS0.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self deny: (visitor checkProject: fileDefAncS1UndAncS0 ).
visitor checkProject: fileDefAncS1UndAncS0.
self deny: visitor isOkay.
self assert: visitor results size equals: 1.
self assert: visitor results first anchorLabel equals: 'ancS0'.
self
Expand Down Expand Up @@ -401,7 +406,8 @@ Just a reference See *@ancS1@* ' ].
file2 ensureCreateFile.

visitor := MicReferenceChecker new.
self assert: (visitor checkDirectory: dir)
visitor checkDirectory: dir.
self assert: visitor isOkay



Expand Down Expand Up @@ -467,7 +473,8 @@ MicReferenceCheckerTest >> testDuplicatedAnchorInDifferentFilesOfTheSameDir [
file2 ensureCreateFile.

visitor := MicReferenceChecker new.
self deny: (visitor checkDirectory: dir).
visitor checkDirectory: dir.
self deny: visitor isOkay.

self assert: visitor duplicatedAnchors size equals: 1.
self
Expand All @@ -488,7 +495,8 @@ MicReferenceCheckerTest >> testDuplicatedAnchors [
| defAncS0TripleAncS1RefAncS1AncS0 checker dict dup1 |
defAncS0TripleAncS1RefAncS1AncS0 := self defAncS0TripleAncS1RefAncS1AncS0.
checker := MicReferenceChecker new.
self deny: (checker checkList: { defAncS0TripleAncS1RefAncS1AncS0 }).
checker checkList: { defAncS0TripleAncS1RefAncS1AncS0 }.
self deny: checker isOkay.
self
assert: (checker results collect: [ :each | each anchorLabel ])
equals: OrderedCollection <- #( 'ancS1' 'ancS1' ).
Expand All @@ -508,7 +516,8 @@ MicReferenceCheckerTest >> testDuplicatedBetweenSectionFigureEq [
| conflictBetweenFigSecEq visitor |
conflictBetweenFigSecEq := self duplicatedFigSecEq.
visitor := MicReferenceChecker new.
self deny: (visitor checkList: { conflictBetweenFigSecEq }).
visitor checkList: { conflictBetweenFigSecEq }.
self deny: visitor isOkay.
self
assert: (visitor results collect: [ :each | each anchorLabel ])
equals: OrderedCollection <- #( 'ancS1' 'ancS0' 'fig2' )
Expand All @@ -521,7 +530,8 @@ MicReferenceCheckerTest >> testDuplicatedBetweenSectionFigureEqInDifferentFile [
duplicatedFigSecEqPart1 := self duplicatedFigSecEqPart1.
duplicatedFigSecEqPart2 := self duplicatedFigSecEqPart2.
visitor := MicReferenceChecker new.
self deny: (visitor checkList: { duplicatedFigSecEqPart1 . duplicatedFigSecEqPart2 }).
visitor checkList: { duplicatedFigSecEqPart1 . duplicatedFigSecEqPart2 }.
self deny: visitor isOkay.
self
assert: (visitor results collect: [ :each | each anchorLabel ])
equals: OrderedCollection <- #( 'ancS1' 'ancS0' 'fig2' )
Expand All @@ -533,7 +543,8 @@ MicReferenceCheckerTest >> testDuplicatedFigures [
| doubleFig1 checker dict dup1 |
doubleFig1 := self defAncS0DoubleFig1Fig2RefAncS1.
checker := MicReferenceChecker new.
self deny: (checker checkList: { doubleFig1 }).
checker checkList: { doubleFig1 }.
self deny: checker isOkay.
self
assert: (checker results collect: [ :each | each anchorLabel ])
equals: OrderedCollection <- #( 'fig1' 'fig1' 'fig1' 'ancS1' ).
Expand All @@ -553,7 +564,8 @@ MicReferenceCheckerTest >> testDuplicatedMaths [
| defAnCS0DoubleEq2DoubleEq1RefEq1 checker dict dup1 dup2 |
defAnCS0DoubleEq2DoubleEq1RefEq1 := self defAnCS0DoubleEq2DoubleEq1RefEq1.
checker := MicReferenceChecker new.
self deny: (checker checkList: { defAnCS0DoubleEq2DoubleEq1RefEq1 }).
checker checkList: { defAnCS0DoubleEq2DoubleEq1RefEq1 }.
self deny: checker isOkay.
self
assert: checker results first source
equals: defAnCS0DoubleEq2DoubleEq1RefEq1 fullName.
Expand All @@ -579,7 +591,7 @@ MicReferenceCheckerTest >> testFullProjectWithFowardAndBackWardRefBetweenTwoFile
self createProjectCorrectReferencesOnTwoFiles.
checker := MicReferenceChecker new.
checker fileSystem: fs.
self assert: (checker checkProject: section1).
checker checkProject: section1.
self assert: checker isOkay
]

Expand All @@ -590,7 +602,8 @@ MicReferenceCheckerTest >> testFullProjectWithReferencesToUnknowAnchor [
self createProjectBadAndCorrectReferences.
checker := MicReferenceChecker new.
checker fileSystem: fs.
self deny: (checker checkProject: section1).
checker checkProject: section1.
self deny: checker isOkay.
self assert: checker results size equals: 2.

dict := checker results groupedBy: [ :each | each class ].
Expand All @@ -617,7 +630,8 @@ See *@anchorSection1@*
'.
visitor := MicReferenceChecker new.
doc accept: visitor.
self assert: visitor isOkay
visitor collectBadReferences.
self assert: visitor isOkay
]

{ #category : 'tests - internal - parse only' }
Expand All @@ -632,6 +646,7 @@ See *@anchorSection1@*
'.
visitor := MicReferenceChecker new.
doc accept: visitor.
visitor collectBadReferences.
self assert: visitor isOkay
]

Expand All @@ -649,6 +664,7 @@ See *@anchorSection1@*
'.
visitor := MicReferenceChecker new.
doc accept: visitor.
visitor collectBadReferences.
self assert: visitor isOkay
]

Expand All @@ -664,6 +680,7 @@ See *@anchorSection1@*
doc fromFile: 'fakedFile'.
visitor := MicReferenceChecker new.
doc accept: visitor.
visitor collectBadReferences.
self deny: visitor isOkay
]

Expand All @@ -674,7 +691,10 @@ MicReferenceCheckerTest >> testRefToUnkS1 [
self refToUnkS1.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self deny: (visitor checkProject: refToUnkS1 )
visitor checkProject: refToUnkS1.
self deny: visitor isOkay


]

{ #category : 'tests - single file' }
Expand All @@ -684,7 +704,8 @@ MicReferenceCheckerTest >> testRefersToUnkAncS1 [
self fileRefAncS1.
visitor := MicReferenceChecker new.
visitor fileSystem: fs.
self deny: (visitor checkProject: refAncS1).
visitor checkProject: refAncS1.
self deny: visitor isOkay.
self assert: visitor results size equals: 1.
self assert: visitor results first anchorLabel equals: 'ancS1'.
self assert: visitor results first source equals: '/fileRefAncS1.md'
Expand Down
73 changes: 73 additions & 0 deletions src/Microdown-BookTester-Tests/MicResultTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Class {
#name : 'MicResultTest',
#superclass : 'TestCase',
#category : 'Microdown-BookTester-Tests',
#package : 'Microdown-BookTester-Tests'
}

{ #category : 'tests' }
MicResultTest >> testExplanationDuplicatedAnchor [

| res |
res := MicDuplicatedAnchorResult new.
res anchorLabel: 'ancS0'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter1.md'.

self
assert: res explanation
equals: 'Anchor ancS0 is duplicated in file: /myDir/chapter1.md'

]

{ #category : 'tests' }
MicResultTest >> testExplanationUndefinedAnchor [

| res |
res := MicUndefinedAnchorResult new.
res anchorLabel: 'ancS0'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter1.md'.

self
assert: res explanation
equals: 'Anchor ancS0 is undefined in file: /myDir/chapter1.md'

]

{ #category : 'tests' }
MicResultTest >> testUndefinedFigureFile [

| res |
self skip.
res := MicUndefinedFigureFileResult new.
res inputFileBlock: (MicInputfileBlock new path: 'myDir/foo.md').
res source: '/myDir/chapter2.md'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter2.md'.

self
assert: res explanation
equals: 'File input myDir/foo.md (in file /myDir/chapter2.md) does not exist'

]

{ #category : 'tests' }
MicResultTest >> testUndefinedInputFile [

| res |
res := MicUndefinedInputFileResult new.
res inputFileBlock: (MicInputfileBlock new path: 'myDir/foo.md').
res source: '/myDir/chapter2.md'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter2.md'.

self
assert: res explanation
equals: 'File input myDir/foo.md (in file /myDir/chapter2.md) does not exist'

]
12 changes: 12 additions & 0 deletions src/Microdown-BookTester/MicAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ MicAnchorResult >> anchorLabel: anObject [

anchorLabel := anObject
]

{ #category : 'accessing' }
MicAnchorResult >> explanation [

^ 'Anchor ', anchorLabel, ' is ', self isWhat, ' in file: ', source

]

{ #category : 'accessing' }
MicAnchorResult >> isWhat [
^ 'undefined'
]
5 changes: 5 additions & 0 deletions src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ Class {
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'accessing' }
MicDuplicatedAnchorResult >> isWhat [
^ 'duplicated'
]
13 changes: 13 additions & 0 deletions src/Microdown-BookTester/MicFileResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ Class {
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'accessing' }
MicFileResult >> explanation [

^ 'File input ', self what,' (in file ', source , ') does not exist'

]

{ #category : 'accessing' }
MicFileResult >> what [

^ self subclassResponsibility
]
14 changes: 5 additions & 9 deletions src/Microdown-BookTester/MicReferenceChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ MicReferenceChecker >> addBadReferenceAnchor: anAnchorReference [
| micResultInstance |
micResultInstance := MicUndefinedAnchorResult new.
micResultInstance
message: (MicUndefinedAnchorResult allMessages at: #anchorIsMissing);
anchorLabel: anAnchorReference anchorLabel;
source: anAnchorReference fromFile.
results add: micResultInstance
Expand All @@ -49,8 +48,6 @@ MicReferenceChecker >> addDuplicatedAnchor: anAnchor [
| micResultInstance |
micResultInstance := MicDuplicatedAnchorResult new.
micResultInstance
message:
(MicDuplicatedAnchorResult allMessages at: #twoAnchorsSameName);
anchorLabel: anAnchor anchorLabel;
source: anAnchor fromFile.
results add: micResultInstance
Expand All @@ -60,7 +57,7 @@ MicReferenceChecker >> addDuplicatedAnchor: anAnchor [
MicReferenceChecker >> checkDirectory: aDir [
"Take the directory, parse all its children with microdown file parser and let the visitor visit each time then return visitor is ok which should be true if every thing is okay, the visitor turned out to treat the many documents that it visits as one, so if anchor is duplicated in another file it will detect that . "

^ self checkList: aDir allFiles
self checkList: aDir allFiles
]

{ #category : 'main API' }
Expand All @@ -71,22 +68,22 @@ MicReferenceChecker >> checkList: aCollection [
| document |
document := Microdown parseFile: each.
document accept: self ].
^ self isOkay
self collectBadReferences.
]

{ #category : 'main API' }
MicReferenceChecker >> checkProject: aDocument [
MicReferenceChecker >> checkProject: aFileReference [

| mainMic collector listOfFiles |
mainMic := Microdown parseFile: aDocument.
mainMic := Microdown parseFile: aFileReference.
collector := MicFileCollector new.
collector
fileSystem: fileSystem;
visit: mainMic.
self handleUndefinedFilesFrom: collector.
listOfFiles := collector visitedDocumentFiles collect: [ :file |
fileSystem referenceTo: file ].
^ self checkList: listOfFiles
self checkList: listOfFiles
]

{ #category : 'visiting' }
Expand Down Expand Up @@ -169,7 +166,6 @@ MicReferenceChecker >> isOk [
{ #category : 'testing' }
MicReferenceChecker >> isOkay [

self collectBadReferences.
^ results isEmpty
]

Expand Down
Loading

0 comments on commit 16716ae

Please sign in to comment.