diff --git a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st index 39586e11..2cb82691 100644 --- a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st +++ b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st @@ -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 ] @@ -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 @@ -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' @@ -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 ] @@ -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. ] @@ -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 @@ -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 @@ -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 @@ -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' ). @@ -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' ) @@ -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' ) @@ -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' ). @@ -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. @@ -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 ] @@ -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 ]. @@ -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' } @@ -632,6 +646,7 @@ See *@anchorSection1@* '. visitor := MicReferenceChecker new. doc accept: visitor. + visitor collectBadReferences. self assert: visitor isOkay ] @@ -649,6 +664,7 @@ See *@anchorSection1@* '. visitor := MicReferenceChecker new. doc accept: visitor. + visitor collectBadReferences. self assert: visitor isOkay ] @@ -664,6 +680,7 @@ See *@anchorSection1@* doc fromFile: 'fakedFile'. visitor := MicReferenceChecker new. doc accept: visitor. + visitor collectBadReferences. self deny: visitor isOkay ] @@ -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' } @@ -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' diff --git a/src/Microdown-BookTester-Tests/MicResultTest.class.st b/src/Microdown-BookTester-Tests/MicResultTest.class.st new file mode 100644 index 00000000..e5650aef --- /dev/null +++ b/src/Microdown-BookTester-Tests/MicResultTest.class.st @@ -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' + +] diff --git a/src/Microdown-BookTester/MicAnchorResult.class.st b/src/Microdown-BookTester/MicAnchorResult.class.st index e5510acb..2c8cfad6 100644 --- a/src/Microdown-BookTester/MicAnchorResult.class.st +++ b/src/Microdown-BookTester/MicAnchorResult.class.st @@ -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' +] diff --git a/src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st b/src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st index b971e594..63fa3d34 100644 --- a/src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st +++ b/src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st @@ -4,3 +4,8 @@ Class { #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' } + +{ #category : 'accessing' } +MicDuplicatedAnchorResult >> isWhat [ + ^ 'duplicated' +] diff --git a/src/Microdown-BookTester/MicFileResult.class.st b/src/Microdown-BookTester/MicFileResult.class.st index 6c6571b0..dbd80f7f 100644 --- a/src/Microdown-BookTester/MicFileResult.class.st +++ b/src/Microdown-BookTester/MicFileResult.class.st @@ -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 +] diff --git a/src/Microdown-BookTester/MicReferenceChecker.class.st b/src/Microdown-BookTester/MicReferenceChecker.class.st index dd4d81b4..b7e7256d 100644 --- a/src/Microdown-BookTester/MicReferenceChecker.class.st +++ b/src/Microdown-BookTester/MicReferenceChecker.class.st @@ -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 @@ -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 @@ -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' } @@ -71,14 +68,14 @@ 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; @@ -86,7 +83,7 @@ MicReferenceChecker >> checkProject: aDocument [ self handleUndefinedFilesFrom: collector. listOfFiles := collector visitedDocumentFiles collect: [ :file | fileSystem referenceTo: file ]. - ^ self checkList: listOfFiles + self checkList: listOfFiles ] { #category : 'visiting' } @@ -169,7 +166,6 @@ MicReferenceChecker >> isOk [ { #category : 'testing' } MicReferenceChecker >> isOkay [ - self collectBadReferences. ^ results isEmpty ] diff --git a/src/Microdown-BookTester/MicResult.class.st b/src/Microdown-BookTester/MicResult.class.st index 22db0448..0ad36942 100644 --- a/src/Microdown-BookTester/MicResult.class.st +++ b/src/Microdown-BookTester/MicResult.class.st @@ -19,54 +19,14 @@ Class { 'source', 'explanation' ], - #classInstVars : [ - 'allMessages' - ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' } -{ #category : 'accessing' } -MicResult class >> allMessages [ - ^ allMessages ifNil: [ - allMessages := Dictionary new. - allMessages - - at: #referenceIsFine put: 'the reference defined correctly and point to a defined anchor'; - at: #false put: 'Failed' ; - at: #true put: 'Passed' ; - at: #anchorIsFine put: 'the anchor is defined correctly and not duplicated elsewhere '; - at: #anchorIsMissing put: 'i represent A reference that refers to a missing anchor'; - at: #twoAnchorsSameName put: '2 anchors are declared with the same name'. - ^ allMessages ] -] - -{ #category : 'accessing' } -MicResult class >> message: aMethodSymbol anchorLabel: aAnchorLabel [ - ^ self new message: (self allMessages at: aMethodSymbol); anchorLabel: aAnchorLabel asString; yourself. -] - -{ #category : 'initialization' } -MicResult class >> reset [ -