Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

815 reference checker should handled the input files the same for the check dir than the check project #892

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,9 @@ Just a reference See *@ancS1@* ' ].
file2 ensureCreateFile.

visitor := MicReferenceChecker new.
visitor rootDirectory: dir.
visitor checkDirectory: dir.
self assert: visitor isOkay



]

{ #category : 'skipped for now' }
Expand Down Expand Up @@ -470,7 +468,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorDir [
{ #category : 'tests - directory api' }
MicReferenceCheckerTest >> testDuplicatedAnchorInDifferentFilesOfTheSameDir [

| file1 file2 visitor dict duplicated |
| file1 file2 visitor dict original duplicated resultFullName |
file1 := dir / 'file1.md'.
file1 writeStreamDo: [ :stream |
stream nextPutAll: '# Section
Expand All @@ -491,6 +489,7 @@ MicReferenceCheckerTest >> testDuplicatedAnchorInDifferentFilesOfTheSameDir [
file2 ensureCreateFile.

visitor := MicReferenceChecker new.
visitor rootDirectory: dir.
visitor checkDirectory: dir.
self deny: visitor isOkay.

Expand All @@ -499,11 +498,16 @@ MicReferenceCheckerTest >> testDuplicatedAnchorInDifferentFilesOfTheSameDir [
assert: visitor duplicatedAnchors first anchorLabel
equals: 'ancS1'.
dict := visitor results groupedBy: [ :each | each class ].
duplicated := (dict at: MicDuplicatedAnchorResult) first.
self
assert: visitor results first sourceFileReference fullName
equals: '/myDirectory/file2.md'.
self assert: duplicated anchorLabel equals: 'ancS1'

original := (dict at: MicDuplicatedAnchorResult) first.
self assert: original anchorLabel equals: 'ancS1'.

duplicated := (dict at: MicDuplicatedAnchorResult) second.
self assert: duplicated anchorLabel equals: 'ancS1'.

resultFullName := visitor results collect: [ :each | each sourceFileReference fullName ].
self
assert: (resultFullName includesAll: #('/myDirectory/file1.md' '/myDirectory/file2.md' ))
]

{ #category : 'tests - duplicated' }
Expand All @@ -528,6 +532,35 @@ MicReferenceCheckerTest >> testDuplicatedAnchors [
self assert: dup1 anchorLabel equals: 'ancS1'
]

{ #category : 'tests - duplicated' }
MicReferenceCheckerTest >> testDuplicatedAnchorsWithCheckListAndCheckDirectory [

| defAncS0TripleAncS1RefAncS1AncS0 checker1 checker2 dict1 dict2 |
defAncS0TripleAncS1RefAncS1AncS0 := self
defAncS0TripleAncS1RefAncS1AncS0.
checker1 := MicReferenceChecker new.
checker1 rootDirectory: dir.
checker1 checkProject: defAncS0TripleAncS1RefAncS1AncS0.

checker2 := MicReferenceChecker new.
checker2 rootDirectory: dir.
checker2 checkDirectory: dir.

self deny: checker1 isOkay.
self deny: checker2 isOkay.

self
assert: (checker1 results collect: [ :each | each anchorLabel ])
equals: (checker2 results collect: [ :each | each anchorLabel ]).

dict1 := checker1 results groupedBy: [ :each | each class ].
dict2 := checker2 results groupedBy: [ :each | each class ].

self
assert: (dict1 at: MicDuplicatedAnchorResult) first sourceFileReference fullName
equals: (dict2 at: MicDuplicatedAnchorResult) first sourceFileReference fullName.
]

{ #category : 'tests - duplicated' }
MicReferenceCheckerTest >> testDuplicatedBetweenSectionFigureEq [

Expand Down
3 changes: 2 additions & 1 deletion src/Microdown-BookTester/MicFileCollector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ MicFileCollector >> visitRoot: micDocument [
[ worklist isEmpty ] whileFalse: [
| currentDocument |
currentDocument := worklist removeFirst.
(visitedFiles includes: currentDocument) ifFalse: [
visitedFileStrings add: currentDocument fromFile fullName.
currentDocument resolveYourself.
visitedFiles add: currentDocument.
Expand All @@ -90,7 +91,7 @@ MicFileCollector >> visitRoot: micDocument [
doc := Microdown parseFile: fr.
worklist addFirst: doc ]
on: FileDoesNotExistException
do: [ unexistingFiles add: inputFile ] ] ] ]
do: [ unexistingFiles add: inputFile ] ] ] ]]
]

{ #category : 'accessing' }
Expand Down
19 changes: 16 additions & 3 deletions src/Microdown-BookTester/MicReferenceChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,21 @@ MicReferenceChecker >> addDuplicatedFirstAnchor: anAnchor [
{ #category : 'main API' }
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked myself why we do not call checkList:
Another question I asked my self was why the collector is not shared between the checkDirectory: and checkProject:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I reused the checkProject: code for having the same semantic in both of checkProject and checkDirectory. chekList: is call at the end of the method.

For the collector who aren't shared between the checkDirectory: and checkProject:, I didn't think about it, maybe I can create a collector variable for the class


"self checkList: aDir allFiles"

| mainMic collector |
collector := MicFileCollector new.
collector rootDirectory: rootDirectory.

aDir allFiles do: [ :aFile |
mainMic := Microdown parseFile: aFile.
collector visit: mainMic ].

self handleUndefinedFilesFrom: collector.
listOfFiles := collector visitedFileStrings collect: [ :file |
rootDirectory resolve: file ].
self checkList: listOfFiles
]

{ #category : 'internal' }
Expand All @@ -90,7 +103,7 @@ MicReferenceChecker >> checkList: aCollection [
{ #category : 'main API' }
MicReferenceChecker >> checkProject: aFileReference [

| mainMic collector |
| mainMic collector |
mainMic := Microdown parseFile: aFileReference.
collector := MicFileCollector new.
collector
Expand Down
Loading