Skip to content

Commit

Permalink
Merge pull request #907 from pillar-markup/906-Even-if-figures-are-re…
Browse files Browse the repository at this point in the history
…ferenced-there-are-reported-as-not-referenced-

906 even if figures are referenced there are reported as not referenced
  • Loading branch information
Ducasse authored Oct 29, 2024
2 parents 8f1f7df + 6907fd8 commit 7f00f6e
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 93 deletions.
102 changes: 74 additions & 28 deletions src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ Class {
'defFig1AndRefToAnsC0',
'defFig1AndRefToAncUnkS0',
'refToUnkS1',
'defCode1AndReferToCode1'
'defCode1AndReferToCode1',
'defFig1'
],
#category : 'Microdown-BookTester-Tests',
#package : 'Microdown-BookTester-Tests'
}

{ #category : 'as yet unclassified' }
MicReferenceCheckerTest >> anchorNames: checker [

^ checker results
select: [ :each | each isKindOf: MicAnchorResult ]
thenCollect: [ :each | each anchorLabel ]
]

{ #category : 'helpers - anchors & references' }
MicReferenceCheckerTest >> defAnCS0DoubleEq2DoubleEq1RefEq1 [

Expand Down Expand Up @@ -134,6 +143,20 @@ See *@Eq1@*
defEq1AndReferToEq1 ensureCreateFile
]

{ #category : 'helpers - anchors & references' }
MicReferenceCheckerTest >> defFig1 [

defFig1 := fs / 'defFig1.md'.
(dir / 'figures' / 'f.png') ensureCreateFile.
defFig1 ensureCreateFile.
defFig1 writeStreamDo: [ :stream |
stream nextPutAll: '# Section 1
![alittle caption. %anchor=Fig1](figures/f.png)
' ]
]

{ #category : 'helpers - anchors & references' }
MicReferenceCheckerTest >> defFig1AndRefFig1 [

Expand All @@ -159,7 +182,7 @@ MicReferenceCheckerTest >> defFig1AndRefToAncS0 [
defFig1AndRefToAnsC0 ensureCreateFile.
defFig1AndRefToAnsC0 writeStreamDo: [ :stream |
stream nextPutAll: '# Section 1
![alittle caption.](figures/f.png anchor=Fig1)
![alittle caption. %anchor=Fig1](figures/f.png)
See *@ancS0@*
Expand Down Expand Up @@ -360,14 +383,15 @@ MicReferenceCheckerTest >> testDefAndReferToAMathEquationInFile [
{ #category : 'tests - single file' }
MicReferenceCheckerTest >> testDefFig1AndRefToAncS0UnknowAnchor [

| visitor |
| visitor badRefs |
self defFig1AndRefToAncS0.
visitor := MicReferenceChecker new.
visitor rootDirectory: dir.
visitor checkProject: defFig1AndRefToAnsC0.
self deny: visitor isOkay.
self assert: visitor results first anchorLabel equals: 'ancS0'.
self assert: visitor results first sourceFileReference fullName equals: '/defFig1AndRefToAncS0.md'
badRefs := visitor results select: [ :each | each isKindOf: MicAnchorResult ].
self assert: badRefs first anchorLabel equals: 'ancS0'.
self assert: badRefs first sourceFileReference fullName equals: '/defFig1AndRefToAncS0.md'
]

{ #category : 'tests - single file ok references' }
Expand All @@ -379,10 +403,10 @@ MicReferenceCheckerTest >> testDefFig1AndRefToAncUnkS0 [
visitor rootDirectory: dir.
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 size equals: 3.
self assert: visitor results second anchorLabel equals: 'ancUnkS0'.
self
assert: visitor results first sourceFileReference fullName
assert: visitor results second sourceFileReference fullName
equals: '/defFig1AndRefToAncUnkS0.md'
]

Expand Down Expand Up @@ -418,9 +442,9 @@ MicReferenceCheckerTest >> testDefS1ButRefersToS0UnknownAnchor [
visitor rootDirectory: dir.
visitor checkProject: fileDefAncS1UndAncS0.
self deny: visitor isOkay.
self assert: visitor results size equals: 1.
self assert: visitor results first anchorLabel equals: 'ancS0'.
self assert: visitor results first sourceFileReference fullName equals: '/fileDefAncS1UndAncS0.md'
self assert: visitor results size equals: 3.
self assert: visitor results second anchorLabel equals: 'ancS0'.
self assert: visitor results second sourceFileReference fullName equals: '/fileDefAncS1UndAncS0.md'

]

Expand Down Expand Up @@ -458,7 +482,7 @@ Just a reference See *@ancS1@* ' ].
{ #category : 'skipped for now' }
MicReferenceCheckerTest >> testDuplicatedAnchorDir [

| dir file1 file2 visitor |
| file1 file2 visitor |
self skip.
dir := (FileSystem workingDirectory / 'myDirectory') asFileReference.
dir ensureCreateDirectory.
Expand Down Expand Up @@ -534,8 +558,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorInDifferentFilesOfTheSameDir [
MicReferenceCheckerTest >> testDuplicatedAnchors [

| defAncS0TripleAncS1RefAncS1AncS0 checker dict dup1 |
defAncS0TripleAncS1RefAncS1AncS0 := self
defAncS0TripleAncS1RefAncS1AncS0.
defAncS0TripleAncS1RefAncS1AncS0 := self defAncS0TripleAncS1RefAncS1AncS0.
checker := MicReferenceChecker new.
checker checkList: { defAncS0TripleAncS1RefAncS1AncS0 }.
self deny: checker isOkay.
Expand All @@ -562,7 +585,7 @@ MicReferenceCheckerTest >> testDuplicatedBetweenSectionFigureEq [
visitor checkList: { conflictBetweenFigSecEq }.
self deny: visitor isOkay.
self
assert: (visitor results collect: [ :each | each anchorLabel ])
assert: (self anchorNames: visitor)
equals: OrderedCollection
<- #( 'ancS1' 'ancS1' 'ancS0' 'ancS0' 'fig2' 'fig2' )
]
Expand All @@ -580,7 +603,7 @@ MicReferenceCheckerTest >> testDuplicatedBetweenSectionFigureEqInDifferentFile [
duplicatedFigSecEqPart2 }.
self deny: visitor isOkay.
self
assert: (visitor results collect: [ :each | each anchorLabel ])
assert: (self anchorNames: visitor)
equals: OrderedCollection
<- #( 'ancS1' 'ancS1' 'ancS0' 'ancS0' 'fig2' 'fig2' )
]
Expand All @@ -595,7 +618,7 @@ MicReferenceCheckerTest >> testDuplicatedFigures [
checker checkList: { doubleFig1 }.
self deny: checker isOkay.
self
assert: (checker results collect: [ :each | each anchorLabel ])
assert: (self anchorNames: checker)
equals:
OrderedCollection <- #( 'fig1' 'fig1' 'fig1' 'fig1' 'ancS1' ).

Expand Down Expand Up @@ -637,15 +660,19 @@ MicReferenceCheckerTest >> testDuplicatedMaths [
{ #category : 'tests - single file' }
MicReferenceCheckerTest >> testFigureFilePathToUnkFile [

| visitor |
| visitor refToUnexistingFiles |
visitor := MicReferenceChecker new.
visitor rootDirectory: dir.
visitor checkProject: self defFig1FilePathToUnk.
self deny: visitor isOkay.
self assert: visitor results size equals: 1.
self assert: visitor results first what equals: 'Fig1'.
self assert: visitor results size equals: 2.
refToUnexistingFiles := (visitor results groupedBy: [ :each | each class name ]) at: #MicUndefinedFigureFileResult.
self assert: refToUnexistingFiles size equals: 1.
self assert: refToUnexistingFiles first what equals: 'figures/f.png'.
self assert: refToUnexistingFiles first figureFileString equals: 'figures/f.png'.

self
assert: visitor results first sourceFileReference fullName
assert: refToUnexistingFiles first sourceFileReference fullName
equals: '/myDirectory/defAndRefFig1.md'
]

Expand Down Expand Up @@ -673,7 +700,7 @@ MicReferenceCheckerTest >> testFullProjectWithReferencesToUnknowAnchor [

dict := checker results groupedBy: [ :each | each class ].

unk := (dict at: MicUndefinedAnchorResult) first.
unk := (dict at: MicReferenceToUnexistingAnchorResult) first.
self assert: unk sourceFileReference fullName equals: '/myDirectory/sections/section2.md'.
self assert: unk anchorLabel equals: 'ancUnkS2'.

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

Expand All @@ -709,10 +736,12 @@ MicReferenceCheckerTest >> testLowLevelReferToAFigure [
See *@anchorSection1@*
'.
doc fromFile: 'file.md' asFileReference.
visitor := MicReferenceChecker new.
doc accept: visitor.
visitor collectBadReferences.
self assert: visitor isOkay
visitor collectReferencesToUnexistingAnchors.
self assert: visitor results first class equals: MicUndefinedFigureFileResult

]

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

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

Expand Down Expand Up @@ -820,7 +849,7 @@ MicReferenceCheckerTest >> testReportingSTONFormatUnknownAnchorDir [
{ #category : 'skipped for now' }
MicReferenceCheckerTest >> testReportingUnknownAnchorDir [

| dir file1 file2 visitor |
| file1 file2 visitor |
self skip.
dir := (FileSystem workingDirectory / 'myDirectory') asFileReference.
dir ensureCreateDirectory.
Expand Down Expand Up @@ -877,3 +906,20 @@ MicReferenceCheckerTest >> testUndefinedInputFilesAreMentionedInResult [
]

]

{ #category : 'tests - single file' }
MicReferenceCheckerTest >> testUnreferencedFigure [

| visitor badRefs unref |
self defFig1.
visitor := MicReferenceChecker new.
visitor rootDirectory: dir.
visitor checkProject: defFig1.
self deny: visitor isOkay.
badRefs := (visitor results groupedBy: [:each | each class name]) at: #MicUnreferencedFigureResult.
unref := badRefs first.
self assert: badRefs size equals: 1.
self assert: unref figurePath equals: 'figures/f.png'.
self assert: unref anchorLabel equals: 'Fig1'.
self assert: unref sourceFileReference fullName equals: '/defFig1.md'
]
13 changes: 7 additions & 6 deletions src/Microdown-BookTester-Tests/MicResultTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MicResultTest >> testExplanationDuplicatedAnchor [
MicResultTest >> testExplanationUndefinedAnchor [

| res |
res := MicUndefinedAnchorResult new.
res := MicReferenceToUnexistingAnchorResult 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"
Expand Down Expand Up @@ -61,13 +61,13 @@ MicResultTest >> testMicBrokenSyncDefinitionResultExplanationWorksWithEmptyInsta
{ #category : 'tests - basic result creation' }
MicResultTest >> testResultCreation [

{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicUndefinedAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicReferenceToUnexistingAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
]

{ #category : 'tests - basic result creation' }
MicResultTest >> testResultCreationSmokeTest [

{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicUndefinedAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicReferenceToUnexistingAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
]

{ #category : 'tests' }
Expand All @@ -93,7 +93,7 @@ MicResultTest >> testSTONFormatExplanationDuplicatedAnchor [
MicResultTest >> testSTONFormatExplanationUndefinedAnchor [

| res association |
res := MicUndefinedAnchorResult new.
res := MicReferenceToUnexistingAnchorResult 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"
Expand All @@ -118,7 +118,7 @@ MicResultTest >> testUndefinedFigureFile [

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

]

Expand All @@ -133,6 +133,7 @@ MicResultTest >> testUndefinedInputFile [

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


]
13 changes: 11 additions & 2 deletions src/Microdown-BookTester/MicAnalysisReportWriter.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"
I'm a little util classes that encapsulates writing reports about analyses.
I'm a little util class that encapsulates writing reports about analyses.
"
Class {
#name : 'MicAnalysisReportWriter',
Expand All @@ -25,7 +25,7 @@ MicAnalysisReportWriter >> buildReportOn: str [
dict := results groupedBy: [ :each | each class ].
dict keysAndValuesDo: [ :k :v |
str cr; nextPutAll: '## ' ;nextPutAll: k headerString; cr; cr.
self reportElementsOn: str.
self reportElements: v on: str.
str cr; cr.
]
]
Expand Down Expand Up @@ -68,6 +68,15 @@ MicAnalysisReportWriter >> report [
]
]

{ #category : 'reporting' }
MicAnalysisReportWriter >> reportElements: partialResults on: aStream [

partialResults
do: [ :each | aStream tab; nextPutAll: each explanation ]
separatedBy: [ aStream cr ]

]

{ #category : 'reporting' }
MicAnalysisReportWriter >> reportElementsOn: aStream [

Expand Down
3 changes: 3 additions & 0 deletions src/Microdown-BookTester/MicAnchorResult.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"
I'm the superclass of problem related to anchors.
"
Class {
#name : 'MicAnchorResult',
#superclass : 'MicResult',
Expand Down
3 changes: 3 additions & 0 deletions src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"
I represent the fact that an achor is defined more than one.
"
Class {
#name : 'MicDuplicatedAnchorResult',
#superclass : 'MicAnchorResult',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-BookTester/MicFileResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
{ #category : 'accessing' }
MicFileResult >> explanation [

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

]

Expand Down
Loading

0 comments on commit 7f00f6e

Please sign in to comment.