From 101460ae4363fdd27c5d6c0c9c411cf47eceae1d Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Tue, 21 May 2024 15:21:00 +0200 Subject: [PATCH 1/9] made the referenceChecker works with files ( saved the file object in the anchor properties to access later ) with tests --- .../MicReferenceChecker.class.st | 57 ++++- .../MicReferenceCheckerTest.class.st | 224 ++++++++++++++++++ 2 files changed, 274 insertions(+), 7 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index c6e500e9..39d35c01 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -16,6 +16,39 @@ Class { #package : 'Microdown-ReferenceChecker' } +{ #category : 'visiting' } +MicReferenceChecker >> attachFile: anElement [ + "get the file from the root of the parsed tree to add it along the anchors later " + |fakeElement| + fakeElement := anElement . + (anElement isKindOf: MicRootBlock ) + ifTrue: [ + ^ (fakeElement propertyAt: #file ifAbsent: [ ]) ] + ifFalse: [ + fakeElement := fakeElement parent . + self attachFile: fakeElement + ] + +] + +{ #category : 'visiting' } +MicReferenceChecker >> checkDir: aDir [ + aDir allFiles children do: [ :each | self checkFile: each ] . + + +] + +{ #category : 'visiting' } +MicReferenceChecker >> checkFile: aFile [ + + |parsedFile| + parsedFile := Microdown parseFile: aFile contents . + parsedFile accept: self. + + + +] + { #category : 'reporting' } MicReferenceChecker >> duplicatedAnchors [ @@ -25,11 +58,11 @@ MicReferenceChecker >> duplicatedAnchors [ { #category : 'visiting' } MicReferenceChecker >> handleAnchorOf: anElement [ - anElement hasAnchor ifTrue: [ - (anchors includes: anElement anchor) - ifTrue: [ duplicatedAnchors add: anElement anchor ] - ifFalse: [ anchors add: anElement anchor ] ] - + anElement hasAnchor ifFalse: [ ^ self ]. + self markAnchorSource: anElement. + (anchors includes: anElement anchor) + ifTrue: [ duplicatedAnchors add: anElement anchor ] + ifFalse: [ anchors add: anElement anchor ] "Pay attention if we want to report all the occurrences of the anchor definition we would have to count the one already included in anchors - Imagine that you have File1/anc1 File2/anc1 and File3/anc1 @@ -52,6 +85,13 @@ MicReferenceChecker >> isOk [ references allSatisfy: [ :each | anchors includes: each ] ] ] +{ #category : 'visiting' } +MicReferenceChecker >> markAnchorSource: anAnchor [ + "get the file from the root of the parsed tree to add it along the anchors later " + anAnchor propertyAt: #file put: (self attachFile: anAnchor ) . + +] + { #category : 'reporting' } MicReferenceChecker >> unknownAnchors [ @@ -65,14 +105,17 @@ MicReferenceChecker >> unknownAnchors [ { #category : 'visiting' } MicReferenceChecker >> visitAnchor: anAnchor [ + self markAnchorSource: anAnchor . (anchors includes: anAnchor label) ifTrue: [ - duplicatedAnchors add: anAnchor label + duplicatedAnchors add: anAnchor label "Pay attention if we want to report all the occurrences of the anchor definition we would have to count the one already included in anchors - Imagine that you have File1/anc1 File2/anc1 and File3/anc1 the reporting should be anc1 is File1, File2 and File3" ] - ifFalse: [ anchors add: anAnchor label ] + ifFalse: [ + anchors add: anAnchor label + ] ] { #category : 'visiting' } diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index 4fe4d320..2a8b42ef 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -20,6 +20,33 @@ See *@anchorSection1@* self assert: visitor isOk. ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testAllReferencesAreCorrectInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 +@anchorSection1 + +See *@anchorSection1@* + +' ] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + + visitor := MicReferenceChecker new. + doc accept: visitor. + self assert: visitor isOk. +] + { #category : 'tests' } MicReferenceCheckerTest >> testReferToAFigure [ @@ -35,6 +62,33 @@ See *@anchorSection1@* self assert: visitor isOk ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReferToAFigureInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 +![alittle caption.](figures/f.png anchor=anchorSection1) + +See *@anchorSection1@* + +' ] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + + visitor := MicReferenceChecker new. + doc accept: visitor. + self assert: visitor isOk. +] + { #category : 'tests' } MicReferenceCheckerTest >> testReferToAMathEquation [ @@ -52,6 +106,35 @@ See *@anchorSection1@* self assert: visitor isOk ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReferToAMathEquationInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 + +$$ %anchor=anchorSection1 +balbalbalb! +$$ +See *@anchorSection1@* + +' ] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + + visitor := MicReferenceChecker new. + doc accept: visitor. + self assert: visitor isOk. +] + { #category : 'tests' } MicReferenceCheckerTest >> testReferToAnUknownAnchor [ @@ -66,6 +149,31 @@ See *@anchorSection1@* self deny: visitor isOk ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReferToAnUknownAnchorInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 + +See *@anchorSection1@* + +' ] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + visitor := MicReferenceChecker new. + doc accept: visitor. + self deny: visitor isOk. +] + { #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedAnchors [ @@ -91,6 +199,42 @@ See *@anchorSection1@* and *@anchorSection0@* self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReportingDuplicatedAnchorsInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +# Section 1 +@anchorSection1 + +# Section 2 +@anchorSection1 + +# Section 3 +@anchorSection1 + +See *@anchorSection1@* and *@anchorSection0@* + +'] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + visitor := MicReferenceChecker new. + doc accept: visitor. + self deny: visitor isOk. + self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') +] + { #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedFigures [ @@ -115,6 +259,41 @@ See *@anchorSection1@* and *@anchorSection3@* equals: OrderedCollection <- #( 'anchorSection1' ) ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +![a caption 1](figures/f.png anchor=anchorSection1) + +![a caption 2](figures/f.png anchor=anchorSection1) + +![a caption 3](figures/f.png anchor=anchorSection2) + +See *@anchorSection1@* and *@anchorSection3@* + +'] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + visitor := MicReferenceChecker new. + doc accept: visitor. +self deny: visitor isOk. + self + assert: visitor duplicatedAnchors + equals: OrderedCollection <- #( 'anchorSection1' ) +] + { #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedMaths [ @@ -149,6 +328,51 @@ See *@anchorSection1@* and *@anchorSection3@* equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ) ] +{ #category : 'tests' } +MicReferenceCheckerTest >> testReportingDuplicatedMathsInFile [ + + | file doc visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +$$ %anchor=anchorSection1 +balbalbalb! +$$ + +$$ %anchor=anchorSection1 +balbalbalb! +$$ + +$$ %anchor=anchorSection1 +balbalbalb! +$$ + +$$ %anchor=anchorSection3 +balbalbalb! +$$ + +See *@anchorSection1@* and *@anchorSection3@* + +'] . + + doc := Microdown parseFile: file contents . + + self assert: (doc isKindOf: MicRootBlock ) . + self assert: doc fromFile equals: file contents . + file ensureDelete . + visitor := MicReferenceChecker new. + doc accept: visitor. + self deny: visitor isOk. + self + assert: visitor duplicatedAnchors + equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ) +] + { #category : 'tests' } MicReferenceCheckerTest >> testReportingUnknownAnchor [ From 56c845fccf0182ccf2d102bf2e66d5743f6c8aba Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Tue, 21 May 2024 16:45:21 +0200 Subject: [PATCH 2/9] checking file method and its tests were not set up correctly . --- .../MicReferenceChecker.class.st | 1 + .../MicReferenceCheckerTest.class.st | 133 ++++++++++-------- 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index 39d35c01..27bc0b02 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -44,6 +44,7 @@ MicReferenceChecker >> checkFile: aFile [ |parsedFile| parsedFile := Microdown parseFile: aFile contents . parsedFile accept: self. + ^ self isOk . diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index 2a8b42ef..be48baed 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -23,7 +23,7 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testAllReferencesAreCorrectInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -36,15 +36,54 @@ See *@anchorSection1@* ' ] . - doc := Microdown parseFile: file contents . - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . + + visitor := MicReferenceChecker new. + self assert: (visitor checkFile: file ). file ensureDelete . +] + +{ #category : 'tests' } +MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ + + | dir file1 file2 | + dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. + dir ensureCreateDirectory . + + file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. + file1 := (FileSystem workingDirectory / 'myDirectory') asFileReference. + file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 '] . + + file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. + file2 := (FileSystem workingDirectory / 'myDirectory') asFileReference. + file2 writeStreamDo: [ :stream | stream nextPutAll: 'See *@anchorSection1@*'] . + + self checkDir: dir . + file1 ensureDelete . + file2 ensureDelete . + + self assert: self isOk. +] + +{ #category : 'tests' } +MicReferenceCheckerTest >> testFile [ + + | file visitor | + file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file ensureCreateFile. + + + + file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 +![alittle caption.](figures/f.png anchor=anchorSection1) + +See *@anchorSection0@* + +' ] . + visitor := MicReferenceChecker new. - doc accept: visitor. - self assert: visitor isOk. + self deny: (visitor checkFile: file ) ] { #category : 'tests' } @@ -65,8 +104,8 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testReferToAFigureInFile [ - | file doc visitor | - file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + | file visitor | + file := (FileSystem workingDirectory / 'myFile2.txt') asFileReference. file ensureCreateFile. @@ -77,16 +116,9 @@ MicReferenceCheckerTest >> testReferToAFigureInFile [ See *@anchorSection1@* ' ] . - - doc := Microdown parseFile: file contents . - - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . - - visitor := MicReferenceChecker new. - doc accept: visitor. - self assert: visitor isOk. + visitor := MicReferenceChecker new. + self assert: (visitor checkFile: file ). + file ensureDelete. ] { #category : 'tests' } @@ -109,7 +141,7 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testReferToAMathEquationInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -124,15 +156,11 @@ See *@anchorSection1@* ' ] . - doc := Microdown parseFile: file contents . - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . visitor := MicReferenceChecker new. - doc accept: visitor. - self assert: visitor isOk. + self assert: (visitor checkFile: file). + file ensureDelete . ] { #category : 'tests' } @@ -152,7 +180,7 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testReferToAnUknownAnchorInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -164,14 +192,10 @@ See *@anchorSection1@* ' ] . - doc := Microdown parseFile: file contents . - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . visitor := MicReferenceChecker new. - doc accept: visitor. - self deny: visitor isOk. + self deny: (visitor checkFile: file) . + file ensureDelete . ] { #category : 'tests - duplicated anchors' } @@ -202,7 +226,7 @@ See *@anchorSection1@* and *@anchorSection0@* { #category : 'tests' } MicReferenceCheckerTest >> testReportingDuplicatedAnchorsInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -224,15 +248,11 @@ See *@anchorSection1@* and *@anchorSection0@* '] . - doc := Microdown parseFile: file contents . - - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . + visitor := MicReferenceChecker new. - doc accept: visitor. - self deny: visitor isOk. - self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') + self deny: (visitor checkFile: file). + self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') . + file ensureDelete . ] { #category : 'tests - duplicated anchors' } @@ -262,7 +282,7 @@ See *@anchorSection1@* and *@anchorSection3@* { #category : 'tests' } MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -280,18 +300,14 @@ MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ See *@anchorSection1@* and *@anchorSection3@* '] . - - doc := Microdown parseFile: file contents . - - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . + . visitor := MicReferenceChecker new. - doc accept: visitor. -self deny: visitor isOk. + self deny: (visitor checkFile: file) . self assert: visitor duplicatedAnchors - equals: OrderedCollection <- #( 'anchorSection1' ) + equals: OrderedCollection <- #( 'anchorSection1' ) . + + file ensureDelete ] { #category : 'tests - duplicated anchors' } @@ -331,7 +347,7 @@ See *@anchorSection1@* and *@anchorSection3@* { #category : 'tests' } MicReferenceCheckerTest >> testReportingDuplicatedMathsInFile [ - | file doc visitor | + | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -359,18 +375,13 @@ $$ See *@anchorSection1@* and *@anchorSection3@* '] . - - doc := Microdown parseFile: file contents . - - self assert: (doc isKindOf: MicRootBlock ) . - self assert: doc fromFile equals: file contents . - file ensureDelete . + visitor := MicReferenceChecker new. - doc accept: visitor. - self deny: visitor isOk. + self deny: (visitor checkFile: file) . self assert: visitor duplicatedAnchors - equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ) + equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ). + file ensureDelete . ] { #category : 'tests' } From 2c8b6460c64ca85fa27736f782005c2ee82c45d3 Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Wed, 22 May 2024 15:35:19 +0200 Subject: [PATCH 3/9] edited check dir so its parse all the files in directory then invite the visitor . its works tests for that will be added next --- .../MicReferenceChecker.class.st | 9 ++++--- .../MicReferenceCheckerTest.class.st | 24 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index 27bc0b02..4ed7e7aa 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -33,8 +33,11 @@ MicReferenceChecker >> attachFile: anElement [ { #category : 'visiting' } MicReferenceChecker >> checkDir: aDir [ - aDir allFiles children do: [ :each | self checkFile: each ] . - + | parsedFile | + (aDir allFiles) do: [ :each | + (parsedFile := Microdown parseFile: (each contents)) accept: self . + ]. + ^ self isOk ] @@ -44,7 +47,7 @@ MicReferenceChecker >> checkFile: aFile [ |parsedFile| parsedFile := Microdown parseFile: aFile contents . parsedFile accept: self. - ^ self isOk . + ^ self isOk diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index be48baed..9ee21cbf 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -46,23 +46,27 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ - | dir file1 file2 | + | dir file1 file2 visitor | dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. dir ensureCreateDirectory . file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. - file1 := (FileSystem workingDirectory / 'myDirectory') asFileReference. - file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 '] . + file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 + @anAnchor + # Section 2 + @anAnchor + '] . + file1 ensureCreateFile . file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. - file2 := (FileSystem workingDirectory / 'myDirectory') asFileReference. - file2 writeStreamDo: [ :stream | stream nextPutAll: 'See *@anchorSection1@*'] . + file2 writeStreamDo: [ :stream | stream nextPutAll: ' # Section 1 + @anAnchor'] . + file2 ensureCreateFile . + + visitor := MicReferenceChecker new. + visitor checkDir: dir. + self assert:( visitor isOk ) . - self checkDir: dir . - file1 ensureDelete . - file2 ensureDelete . - - self assert: self isOk. ] { #category : 'tests' } From a48addd0210bda87f81d54d4042c683dd9ab73e8 Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Wed, 22 May 2024 15:45:50 +0200 Subject: [PATCH 4/9] the tests for directory are working --- .../MicReferenceCheckerTest.class.st | 82 +++++++++++++++++-- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index 9ee21cbf..22b325e9 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -51,21 +51,57 @@ MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ dir ensureCreateDirectory . file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. - file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 - @anAnchor - # Section 2 - @anAnchor - '] . + file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +# Section 1 +@anchorSection1 + + +' ] . + file1 ensureCreateFile . + + file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. + file2 writeStreamDo: [ :stream | stream nextPutAll: ' See *@anchorSection1@* and *@anchorSection1@*'] . + file2 ensureCreateFile . + + visitor := MicReferenceChecker new. + self assert:( visitor checkDir: dir ) . + +] + +{ #category : 'tests' } +MicReferenceCheckerTest >> testDuplicatedAnchorDir [ + + | dir file1 file2 visitor | + dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. + dir ensureCreateDirectory . + + file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. + file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +# Section 1 +@anchorSection1 + + +' ] . file1 ensureCreateFile . file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. - file2 writeStreamDo: [ :stream | stream nextPutAll: ' # Section 1 - @anAnchor'] . + file2 writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection3 + +# Section 4 +@anchorSection1 + + +'] . file2 ensureCreateFile . visitor := MicReferenceChecker new. - visitor checkDir: dir. - self assert:( visitor isOk ) . + + self deny: ( visitor checkDir: dir ) . ] @@ -406,3 +442,31 @@ See *@anchorSection1@* and *@anchorSection2@* self deny: visitor isOk. self assert: visitor unknownAnchors equals: (OrderedCollection <- #('anchorSection2')) ] + +{ #category : 'tests' } +MicReferenceCheckerTest >> testReportingUnknownAnchorDir [ + + | dir file1 file2 visitor | + dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. + dir ensureCreateDirectory . + + file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. + file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section +@anchorSection0 + +# Section 1 +@anchorSection1 + + +' ] . + file1 ensureCreateFile . + + file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. + file2 writeStreamDo: [ :stream | stream nextPutAll: ' See *@anchorSection1@* and *@anchorSection2@*'] . + file2 ensureCreateFile . + + visitor := MicReferenceChecker new. + + self deny: ( visitor checkDir: dir ) . + +] From ccf4cc453e38888597bb9215453aedec5c69e9e9 Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Wed, 22 May 2024 15:55:26 +0200 Subject: [PATCH 5/9] added comments --- .../MicReferenceChecker.class.st | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index 4ed7e7aa..3e0bcafd 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -18,7 +18,9 @@ Class { { #category : 'visiting' } MicReferenceChecker >> attachFile: anElement [ - "get the file from the root of the parsed tree to add it along the anchors later " + + "get the file from the root of the parsed tree to add it along the anchors later so we know in what file are the anchors or elements that caused the problem , what worth noting here is in the cases where anchor is not an object that will not work " + |fakeElement| fakeElement := anElement . (anElement isKindOf: MicRootBlock ) @@ -33,10 +35,15 @@ MicReferenceChecker >> attachFile: anElement [ { #category : 'visiting' } MicReferenceChecker >> checkDir: 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 . " + | parsedFile | + (aDir allFiles) do: [ :each | (parsedFile := Microdown parseFile: (each contents)) accept: self . ]. + ^ self isOk ] @@ -44,6 +51,8 @@ MicReferenceChecker >> checkDir: aDir [ { #category : 'visiting' } MicReferenceChecker >> checkFile: aFile [ + " will parse the given file and invite the visitor and return visitor isOk value " + |parsedFile| parsedFile := Microdown parseFile: aFile contents . parsedFile accept: self. From 4d4c37cf8bfab129a034a4828b8b4f6503fc85cd Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Thu, 23 May 2024 11:10:12 +0200 Subject: [PATCH 6/9] polished tests --- .../MicReferenceCheckerTest.class.st | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index 22b325e9..4d328660 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -17,7 +17,7 @@ See *@anchorSection1@* '. visitor := MicReferenceChecker new. doc accept: visitor. - self assert: visitor isOk. + self assert: visitor isOk ] { #category : 'tests' } @@ -40,7 +40,7 @@ See *@anchorSection1@* visitor := MicReferenceChecker new. self assert: (visitor checkFile: file ). - file ensureDelete . + file ensureDelete ] { #category : 'tests' } @@ -67,6 +67,9 @@ MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ visitor := MicReferenceChecker new. self assert:( visitor checkDir: dir ) . + file1 ensureDelete. + file2 ensureDelete. + dir ensureDelete ] @@ -158,7 +161,7 @@ See *@anchorSection1@* ' ] . visitor := MicReferenceChecker new. self assert: (visitor checkFile: file ). - file ensureDelete. + file ensureDelete ] { #category : 'tests' } @@ -200,7 +203,7 @@ See *@anchorSection1@* visitor := MicReferenceChecker new. self assert: (visitor checkFile: file). - file ensureDelete . + file ensureDelete ] { #category : 'tests' } @@ -235,7 +238,7 @@ See *@anchorSection1@* visitor := MicReferenceChecker new. self deny: (visitor checkFile: file) . - file ensureDelete . + file ensureDelete ] { #category : 'tests - duplicated anchors' } @@ -292,7 +295,7 @@ See *@anchorSection1@* and *@anchorSection0@* visitor := MicReferenceChecker new. self deny: (visitor checkFile: file). self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') . - file ensureDelete . + file ensureDelete ] { #category : 'tests - duplicated anchors' } @@ -421,7 +424,7 @@ See *@anchorSection1@* and *@anchorSection3@* self assert: visitor duplicatedAnchors equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ). - file ensureDelete . + file ensureDelete ] { #category : 'tests' } @@ -469,4 +472,8 @@ MicReferenceCheckerTest >> testReportingUnknownAnchorDir [ self deny: ( visitor checkDir: dir ) . + file1 ensureDelete. + file2 ensureDelete. + dir ensureDelete + ] From a66494641ac2a98f53cdfc7fa271a399aa06acee Mon Sep 17 00:00:00 2001 From: YASSER <75129790+melkiyasser@users.noreply.github.com> Date: Thu, 23 May 2024 11:33:38 +0200 Subject: [PATCH 7/9] more polishing --- .../MicReferenceCheckerTest.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index 4d328660..d0e447ee 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -73,7 +73,7 @@ MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ ] -{ #category : 'tests' } +{ #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testDuplicatedAnchorDir [ | dir file1 file2 visitor | @@ -104,7 +104,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorDir [ visitor := MicReferenceChecker new. - self deny: ( visitor checkDir: dir ) . + self deny: ( visitor checkDir: dir ) ] @@ -266,7 +266,7 @@ See *@anchorSection1@* and *@anchorSection0@* self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') ] -{ #category : 'tests' } +{ #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedAnchorsInFile [ | file visitor | @@ -322,7 +322,7 @@ See *@anchorSection1@* and *@anchorSection3@* equals: OrderedCollection <- #( 'anchorSection1' ) ] -{ #category : 'tests' } +{ #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ | file visitor | @@ -387,7 +387,7 @@ See *@anchorSection1@* and *@anchorSection3@* equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ) ] -{ #category : 'tests' } +{ #category : 'tests - duplicated anchors' } MicReferenceCheckerTest >> testReportingDuplicatedMathsInFile [ | file visitor | From 24c0d76859b5b113a03197f875a0c2b64a65efa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Thu, 23 May 2024 14:00:09 +0200 Subject: [PATCH 8/9] Fixing ref with Yasser --- .../MicReferenceChecker.class.st | 62 ++++++++----------- .../MicReferenceCheckerTest.class.st | 8 +-- src/Microdown/MicAnchorBlock.class.st | 6 ++ src/Microdown/MicInlineBlockWithUrl.class.st | 6 ++ src/Microdown/MicMathBlock.class.st | 6 ++ src/Microdown/Microdown.class.st | 2 +- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index 3e0bcafd..e9f450dc 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -34,14 +34,12 @@ MicReferenceChecker >> attachFile: anElement [ ] { #category : 'visiting' } -MicReferenceChecker >> checkDir: 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 . " +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 . " - | parsedFile | - - (aDir allFiles) do: [ :each | - (parsedFile := Microdown parseFile: (each contents)) accept: self . + | parsedFile | + aDir allFiles do: [ :each | + (parsedFile := Microdown parseFile: each) accept: self. ]. ^ self isOk @@ -50,11 +48,10 @@ MicReferenceChecker >> checkDir: aDir [ { #category : 'visiting' } MicReferenceChecker >> checkFile: aFile [ + "Will parse the given file and invite the visitor and return visitor isOk value" - " will parse the given file and invite the visitor and return visitor isOk value " - - |parsedFile| - parsedFile := Microdown parseFile: aFile contents . + | parsedFile | + parsedFile := Microdown parseFile: aFile. parsedFile accept: self. ^ self isOk @@ -72,14 +69,19 @@ MicReferenceChecker >> duplicatedAnchors [ MicReferenceChecker >> handleAnchorOf: anElement [ anElement hasAnchor ifFalse: [ ^ self ]. - self markAnchorSource: anElement. - (anchors includes: anElement anchor) - ifTrue: [ duplicatedAnchors add: anElement anchor ] - ifFalse: [ anchors add: anElement anchor ] - "Pay attention if we want to report all the occurrences of the - anchor definition we would have to count the one already included - in anchors - Imagine that you have File1/anc1 File2/anc1 and File3/anc1 - the reporting should be anc1 is File1, File2 and File3" + + (self hasAlreadyDefinedAs: anElement) + ifTrue: [ duplicatedAnchors add: anElement ]. + anchors add: anElement + +] + +{ #category : 'visiting' } +MicReferenceChecker >> hasAlreadyDefinedAs: anAnchor [ + + ^ (anchors + detect: [ :each | each label = anAnchor anchorLabel ] + ifNone: [ #( ) ]) isNotEmpty ] { #category : 'initialization' } @@ -98,13 +100,6 @@ MicReferenceChecker >> isOk [ references allSatisfy: [ :each | anchors includes: each ] ] ] -{ #category : 'visiting' } -MicReferenceChecker >> markAnchorSource: anAnchor [ - "get the file from the root of the parsed tree to add it along the anchors later " - anAnchor propertyAt: #file put: (self attachFile: anAnchor ) . - -] - { #category : 'reporting' } MicReferenceChecker >> unknownAnchors [ @@ -118,17 +113,10 @@ MicReferenceChecker >> unknownAnchors [ { #category : 'visiting' } MicReferenceChecker >> visitAnchor: anAnchor [ - self markAnchorSource: anAnchor . - (anchors includes: anAnchor label) - ifTrue: [ - duplicatedAnchors add: anAnchor label - "Pay attention if we want to report all the occurrences of the - anchor definition we would have to count the one already included - in anchors - Imagine that you have File1/anc1 File2/anc1 and File3/anc1 - the reporting should be anc1 is File1, File2 and File3" ] - ifFalse: [ - anchors add: anAnchor label - ] + | isAlready | + isAlready := self hasAlreadyDefinedAs: anAnchor. + isAlready ifTrue: [ duplicatedAnchors add: anAnchor ]. + anchors add: anAnchor ] { #category : 'visiting' } diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index d0e447ee..ddc6b6dc 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -66,7 +66,7 @@ MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ file2 ensureCreateFile . visitor := MicReferenceChecker new. - self assert:( visitor checkDir: dir ) . + self assert:( visitor checkDirectory: dir ) . file1 ensureDelete. file2 ensureDelete. dir ensureDelete @@ -78,7 +78,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorDir [ | dir file1 file2 visitor | dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. - dir ensureCreateDirectory . + dir ensureCreateDirectory. file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section @@ -104,7 +104,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorDir [ visitor := MicReferenceChecker new. - self deny: ( visitor checkDir: dir ) + self deny: ( visitor checkDirectory: dir ) ] @@ -470,7 +470,7 @@ MicReferenceCheckerTest >> testReportingUnknownAnchorDir [ visitor := MicReferenceChecker new. - self deny: ( visitor checkDir: dir ) . + self deny: ( visitor checkDirectory: dir ) . file1 ensureDelete. file2 ensureDelete. diff --git a/src/Microdown/MicAnchorBlock.class.st b/src/Microdown/MicAnchorBlock.class.st index 4fe06945..c4da746c 100644 --- a/src/Microdown/MicAnchorBlock.class.st +++ b/src/Microdown/MicAnchorBlock.class.st @@ -32,6 +32,12 @@ MicAnchorBlock >> addLineAndReturnNextNode: line [ ^ self ] +{ #category : 'accessing' } +MicAnchorBlock >> anchorLabel [ + "This should only be invoked when checking references" + ^ self label +] + { #category : 'testing' } MicAnchorBlock >> hasLabel [ label ifNil: [ ^ false ]. diff --git a/src/Microdown/MicInlineBlockWithUrl.class.st b/src/Microdown/MicInlineBlockWithUrl.class.st index 1c105c1c..92787615 100644 --- a/src/Microdown/MicInlineBlockWithUrl.class.st +++ b/src/Microdown/MicInlineBlockWithUrl.class.st @@ -39,6 +39,12 @@ MicInlineBlockWithUrl >> anchor: aString [ arguments removeKey: #label ifAbsent: []. ] +{ #category : 'handle' } +MicInlineBlockWithUrl >> anchorLabel [ + "This should only be invoked when checking references" + ^ self anchor +] + { #category : 'accessing' } MicInlineBlockWithUrl >> argumentAt: aKey ifPresent: aBlock [ "Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer self." diff --git a/src/Microdown/MicMathBlock.class.st b/src/Microdown/MicMathBlock.class.st index bd0d2d28..50fc57c3 100644 --- a/src/Microdown/MicMathBlock.class.st +++ b/src/Microdown/MicMathBlock.class.st @@ -62,6 +62,12 @@ MicMathBlock >> anchor: aString [ arguments removeKey: #label ifAbsent: []. ] +{ #category : 'handle' } +MicMathBlock >> anchorLabel [ + "This should only be invoked when checking references" + ^ self anchor +] + { #category : 'handle' } MicMathBlock >> extractFirstLineFrom: aLine [ diff --git a/src/Microdown/Microdown.class.st b/src/Microdown/Microdown.class.st index 3bcc9cc6..36a91619 100644 --- a/src/Microdown/Microdown.class.st +++ b/src/Microdown/Microdown.class.st @@ -156,7 +156,7 @@ Microdown >> parse: aStreamOrString [ Microdown >> parseFile: aFile [ |root| - root := MicrodownParser parse: (aFile contents). + root := MicrodownParser parse: aFile contents. root fromFile: aFile fullName. ^ root From 4fa59cba29cf176a20bb5838365bd77070ff472b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Thu, 23 May 2024 15:13:03 +0200 Subject: [PATCH 9/9] Fixed references --- .../MicReferenceChecker.class.st | 45 ++++------- .../MicReferenceCheckerTest.class.st | 80 +++++++------------ src/Microdown/MicAnchorBlock.class.st | 8 ++ .../MicAnchorReferenceBlock.class.st | 6 ++ 4 files changed, 59 insertions(+), 80 deletions(-) diff --git a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st index e9f450dc..89c4356b 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceChecker.class.st @@ -16,23 +16,6 @@ Class { #package : 'Microdown-ReferenceChecker' } -{ #category : 'visiting' } -MicReferenceChecker >> attachFile: anElement [ - - "get the file from the root of the parsed tree to add it along the anchors later so we know in what file are the anchors or elements that caused the problem , what worth noting here is in the cases where anchor is not an object that will not work " - - |fakeElement| - fakeElement := anElement . - (anElement isKindOf: MicRootBlock ) - ifTrue: [ - ^ (fakeElement propertyAt: #file ifAbsent: [ ]) ] - ifFalse: [ - fakeElement := fakeElement parent . - self attachFile: fakeElement - ] - -] - { #category : 'visiting' } 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 . " @@ -41,7 +24,6 @@ MicReferenceChecker >> checkDirectory: aDir [ aDir allFiles do: [ :each | (parsedFile := Microdown parseFile: each) accept: self. ]. - ^ self isOk ] @@ -69,7 +51,6 @@ MicReferenceChecker >> duplicatedAnchors [ MicReferenceChecker >> handleAnchorOf: anElement [ anElement hasAnchor ifFalse: [ ^ self ]. - (self hasAlreadyDefinedAs: anElement) ifTrue: [ duplicatedAnchors add: anElement ]. anchors add: anElement @@ -79,9 +60,12 @@ MicReferenceChecker >> handleAnchorOf: anElement [ { #category : 'visiting' } MicReferenceChecker >> hasAlreadyDefinedAs: anAnchor [ - ^ (anchors - detect: [ :each | each label = anAnchor anchorLabel ] - ifNone: [ #( ) ]) isNotEmpty + | alreadyDefined | + alreadyDefined := false. + anchors do: + [ :each | each anchorLabel = anAnchor anchorLabel + ifTrue: [ alreadyDefined := true ] ]. + ^ alreadyDefined ] { #category : 'initialization' } @@ -97,17 +81,20 @@ MicReferenceChecker >> initialize [ MicReferenceChecker >> isOk [ ^ duplicatedAnchors isEmpty and: [ - references allSatisfy: [ :each | anchors includes: each ] ] + references allSatisfy: [ :each | self hasAlreadyDefinedAs: each ] ] ] { #category : 'reporting' } MicReferenceChecker >> unknownAnchors [ - | unk | - unk := references copy. - anchors do: [ :each | - unk remove: each ifAbsent: [ ] ]. - ^ unk + | unknown ref | + unknown := OrderedCollection new. + ref := references copy. + ref do: [ :ref | + (anchors noneSatisfy: [ :each | + ref anchorLabel = each anchorLabel ]) + ifTrue: [ unknown add: ref ] ]. + ^ unknown ] { #category : 'visiting' } @@ -122,7 +109,7 @@ MicReferenceChecker >> visitAnchor: anAnchor [ { #category : 'visiting' } MicReferenceChecker >> visitAnchorReference: anAnchorReference [ - references add: anAnchorReference bodyString + references add: anAnchorReference ] { #category : 'visiting' } diff --git a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st index ddc6b6dc..3daef1f4 100644 --- a/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st +++ b/src/Microdown-ReferenceChecker/MicReferenceCheckerTest.class.st @@ -24,11 +24,8 @@ See *@anchorSection1@* MicReferenceCheckerTest >> testAllReferencesAreCorrectInFile [ | file visitor | - file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file := (FileSystem memory / 'myFile.txt') asFileReference. file ensureCreateFile. - - - file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 @anchorSection1 @@ -46,10 +43,9 @@ See *@anchorSection1@* { #category : 'tests' } MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ - | dir file1 file2 visitor | + | dir file1 file2 visitor | dir := (FileSystem workingDirectory / 'myDirectory') asFileReference. - dir ensureCreateDirectory . - + dir ensureCreateDirectory. file1 := (FileSystem workingDirectory / 'myDirectory' / 'file1.txt') asFileReference. file1 writeStreamDo: [ :stream | stream nextPutAll: '# Section @anchorSection0 @@ -57,19 +53,14 @@ MicReferenceCheckerTest >> testAllReferencesAreCorrectinDir [ # Section 1 @anchorSection1 - ' ] . - file1 ensureCreateFile . file2 := (FileSystem workingDirectory / 'myDirectory' / 'file2.txt') asFileReference. file2 writeStreamDo: [ :stream | stream nextPutAll: ' See *@anchorSection1@* and *@anchorSection1@*'] . - file2 ensureCreateFile . + file2 ensureCreateFile. visitor := MicReferenceChecker new. - self assert:( visitor checkDirectory: dir ) . - file1 ensureDelete. - file2 ensureDelete. - dir ensureDelete + self assert: (visitor checkDirectory: dir). ] @@ -112,21 +103,16 @@ MicReferenceCheckerTest >> testDuplicatedAnchorDir [ MicReferenceCheckerTest >> testFile [ | file visitor | - file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file := (FileSystem memory / 'myFile.txt') asFileReference. file ensureCreateFile. - - - file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 ![alittle caption.](figures/f.png anchor=anchorSection1) See *@anchorSection0@* -' ] . - - +' ]. visitor := MicReferenceChecker new. - self deny: (visitor checkFile: file ) + self deny: (visitor checkFile: file) ] { #category : 'tests' } @@ -148,20 +134,16 @@ See *@anchorSection1@* MicReferenceCheckerTest >> testReferToAFigureInFile [ | file visitor | - file := (FileSystem workingDirectory / 'myFile2.txt') asFileReference. + file := (FileSystem memory / 'myFile2.txt') asFileReference. file ensureCreateFile. - - - file writeStreamDo: [ :stream | stream nextPutAll: '# Section 1 ![alittle caption.](figures/f.png anchor=anchorSection1) See *@anchorSection1@* -' ] . +' ]. visitor := MicReferenceChecker new. - self assert: (visitor checkFile: file ). - file ensureDelete + self assert: (visitor checkFile: file). ] { #category : 'tests' } @@ -185,7 +167,7 @@ See *@anchorSection1@* MicReferenceCheckerTest >> testReferToAMathEquationInFile [ | file visitor | - file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file := (FileSystem memory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -224,7 +206,7 @@ See *@anchorSection1@* MicReferenceCheckerTest >> testReferToAnUknownAnchorInFile [ | file visitor | - file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. + file := (FileSystem memory / 'myFile.txt') asFileReference. file ensureCreateFile. @@ -263,7 +245,7 @@ See *@anchorSection1@* and *@anchorSection0@* visitor := MicReferenceChecker new. doc accept: visitor. self deny: visitor isOk. - self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') + self assert: (visitor duplicatedAnchors collect: [:each | each anchorLabel ]) equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') ] { #category : 'tests - duplicated anchors' } @@ -294,8 +276,10 @@ See *@anchorSection1@* and *@anchorSection0@* visitor := MicReferenceChecker new. self deny: (visitor checkFile: file). - self assert: visitor duplicatedAnchors equals: OrderedCollection <- #('anchorSection1' 'anchorSection1') . - file ensureDelete + self + assert: (visitor duplicatedAnchors collect: [:each | each anchorLabel]) + equals: OrderedCollection <- #('anchorSection1' 'anchorSection1'). + file ensureDelete ] { #category : 'tests - duplicated anchors' } @@ -318,7 +302,7 @@ See *@anchorSection1@* and *@anchorSection3@* doc accept: visitor. self deny: visitor isOk. self - assert: visitor duplicatedAnchors + assert: (visitor duplicatedAnchors collect: [ :each | each anchorLabel ]) equals: OrderedCollection <- #( 'anchorSection1' ) ] @@ -328,9 +312,6 @@ MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. - - - file writeStreamDo: [ :stream | stream nextPutAll: '# Section @anchorSection0 @@ -342,14 +323,12 @@ MicReferenceCheckerTest >> testReportingDuplicatedFiguresInFile [ See *@anchorSection1@* and *@anchorSection3@* -'] . - . +']. visitor := MicReferenceChecker new. - self deny: (visitor checkFile: file) . + self deny: (visitor checkFile: file). self - assert: visitor duplicatedAnchors - equals: OrderedCollection <- #( 'anchorSection1' ) . - + assert: (visitor duplicatedAnchors collect: [ :each | each anchorLabel ]) + equals: OrderedCollection <- #( 'anchorSection1' ). file ensureDelete ] @@ -383,7 +362,7 @@ See *@anchorSection1@* and *@anchorSection3@* doc accept: visitor. self deny: visitor isOk. self - assert: visitor duplicatedAnchors + assert: (visitor duplicatedAnchors collect: [ :each | each anchorLabel ]) equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ) ] @@ -393,9 +372,6 @@ MicReferenceCheckerTest >> testReportingDuplicatedMathsInFile [ | file visitor | file := (FileSystem workingDirectory / 'myFile.txt') asFileReference. file ensureCreateFile. - - - file writeStreamDo: [ :stream | stream nextPutAll: '# Section @anchorSection0 @@ -420,9 +396,9 @@ See *@anchorSection1@* and *@anchorSection3@* '] . visitor := MicReferenceChecker new. - self deny: (visitor checkFile: file) . + self deny: (visitor checkFile: file). self - assert: visitor duplicatedAnchors + assert: (visitor duplicatedAnchors collect: [ :each | each anchorLabel ]) equals: OrderedCollection <- #( 'anchorSection1' 'anchorSection1' ). file ensureDelete ] @@ -443,7 +419,9 @@ See *@anchorSection1@* and *@anchorSection2@* visitor := MicReferenceChecker new. doc accept: visitor. self deny: visitor isOk. - self assert: visitor unknownAnchors equals: (OrderedCollection <- #('anchorSection2')) + self + assert: (visitor unknownAnchors collect: [ :each | each anchorLabel ]) + equals: (OrderedCollection <- #('anchorSection2')) ] { #category : 'tests' } diff --git a/src/Microdown/MicAnchorBlock.class.st b/src/Microdown/MicAnchorBlock.class.st index c4da746c..5d460f32 100644 --- a/src/Microdown/MicAnchorBlock.class.st +++ b/src/Microdown/MicAnchorBlock.class.st @@ -55,6 +55,14 @@ MicAnchorBlock >> label: aLabel [ ] +{ #category : 'printing' } +MicAnchorBlock >> printOn: aStream [ + + super printOn: aStream. + self hasLabel + ifTrue: [ aStream nextPutAll: ' (', self label, ')' ] +] + { #category : 'accessing' } MicAnchorBlock >> target [ ^ target diff --git a/src/Microdown/MicAnchorReferenceBlock.class.st b/src/Microdown/MicAnchorReferenceBlock.class.st index 2b100a0e..f1f7505f 100644 --- a/src/Microdown/MicAnchorReferenceBlock.class.st +++ b/src/Microdown/MicAnchorReferenceBlock.class.st @@ -34,6 +34,12 @@ MicAnchorReferenceBlock >> accept: aVisitor [ ^ aVisitor visitAnchorReference: self ] +{ #category : 'accessing' } +MicAnchorReferenceBlock >> anchorLabel [ + + ^ bodyString +] + { #category : 'accessing' } MicAnchorReferenceBlock >> reference [