From 991089608d9579052333bd5ffa4a9e3ddce265e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Wed, 14 Aug 2024 13:30:08 +0200 Subject: [PATCH] Fixing fileSystem --- .../MicFileCollectorTest.class.st | 2 +- .../MicReferenceCheckerTest.class.st | 27 +++++++------------ .../MicFileCollector.class.st | 18 ++++++++++--- .../MicReferenceChecker.class.st | 16 +++++++---- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st b/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st index 37af5f55..0c0c490f 100644 --- a/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st +++ b/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st @@ -18,7 +18,7 @@ MicFileCollectorTest >> startVisitingFromTheRoot: root [ mainMic := Microdown parseFile: root. visitor := MicFileCollector new. visitor - fileSystem: fs; + rootDirectory: dir; visit: mainMic. ] diff --git a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st index 2cb82691..561af919 100644 --- a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st +++ b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st @@ -294,22 +294,13 @@ See *@ancS1@* ' ] ] -{ #category : 'running' } -MicReferenceCheckerTest >> setUp [ - - super setUp. - fs := self fileSystem. - dir := fs / 'myDirectory'. - dir ensureCreateDirectory -] - { #category : 'tests - single file ok references' } MicReferenceCheckerTest >> testDefAndReferToAMathEquationInFile [ | visitor | self defEq1AndReferToEq1. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: defEq1AndReferToEq1. self assert: visitor isOkay. self assert: visitor results isEmpty @@ -321,7 +312,7 @@ MicReferenceCheckerTest >> testDefFig1AndRefToAncS0UnknowAnchor [ | visitor | self defFig1AndRefToAncS0. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: defFig1AndRefToAnsC0. self deny: visitor isOkay. self assert: visitor results first anchorLabel equals: 'ancS0'. @@ -349,7 +340,7 @@ MicReferenceCheckerTest >> testDefFig1AndReferToFig1 [ | visitor | self defFig1AndRefFig1. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: defAndRefFig1. self assert: visitor isOkay. self assert: visitor results isEmpty @@ -372,7 +363,7 @@ MicReferenceCheckerTest >> testDefS1ButRefersToS0UnknownAnchor [ | visitor | self fileDefAncS1UndAncS0. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: fileDefAncS1UndAncS0. self deny: visitor isOkay. self assert: visitor results size equals: 1. @@ -590,7 +581,7 @@ MicReferenceCheckerTest >> testFullProjectWithFowardAndBackWardRefBetweenTwoFile | checker | self createProjectCorrectReferencesOnTwoFiles. checker := MicReferenceChecker new. - checker fileSystem: fs. + checker rootDirectory: dir. checker checkProject: section1. self assert: checker isOkay ] @@ -601,7 +592,7 @@ MicReferenceCheckerTest >> testFullProjectWithReferencesToUnknowAnchor [ | checker dict unk undefined | self createProjectBadAndCorrectReferences. checker := MicReferenceChecker new. - checker fileSystem: fs. + checker rootDirectory: dir. checker checkProject: section1. self deny: checker isOkay. self assert: checker results size equals: 2. @@ -690,7 +681,7 @@ MicReferenceCheckerTest >> testRefToUnkS1 [ | visitor | self refToUnkS1. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: refToUnkS1. self deny: visitor isOkay @@ -703,7 +694,7 @@ MicReferenceCheckerTest >> testRefersToUnkAncS1 [ | visitor | self fileRefAncS1. visitor := MicReferenceChecker new. - visitor fileSystem: fs. + visitor rootDirectory: dir. visitor checkProject: refAncS1. self deny: visitor isOkay. self assert: visitor results size equals: 1. @@ -750,7 +741,7 @@ MicReferenceCheckerTest >> testUndefinedInputFilesAreMentionedInResult [ | checker | self createProjectWithUnexistingSection3And5. checker := MicReferenceChecker new. - checker fileSystem: fs. + checker rootDirectory: dir. checker checkProject: section1. self assert: checker results size equals: 3. diff --git a/src/Microdown-BookTester/MicFileCollector.class.st b/src/Microdown-BookTester/MicFileCollector.class.st index a5e3a083..001a52b8 100644 --- a/src/Microdown-BookTester/MicFileCollector.class.st +++ b/src/Microdown-BookTester/MicFileCollector.class.st @@ -13,7 +13,7 @@ Class { #name : 'MicFileCollector', #superclass : 'MicrodownVisitor', #instVars : [ - 'fileSystem', + 'rootDirectory', 'visited', 'unexistingFiles', 'inputFiles' @@ -38,11 +38,23 @@ MicFileCollector >> fileSystem: aFileSystem [ MicFileCollector >> initialize [ super initialize. - fileSystem := FileSystem disk. + rootDirectory := FileSystem workingDirectory. visited := Set new. unexistingFiles := Set new. ] +{ #category : 'accessing' } +MicFileCollector >> rootDirectory [ + + ^ rootDirectory +] + +{ #category : 'accessing' } +MicFileCollector >> rootDirectory: aFileReference [ + + rootDirectory := aFileReference +] + { #category : 'accessing' } MicFileCollector >> unexistingFiles [ @@ -75,7 +87,7 @@ MicFileCollector >> visitRoot: micDocument [ inputFiles do: [ :inputFile | | fr doc | "later we will have to fix this ugly expression" - fr := self fileSystem referenceTo: + fr := self rootDirectory resolve: (inputFile arguments at: 'path') uri asFileReference pathString. diff --git a/src/Microdown-BookTester/MicReferenceChecker.class.st b/src/Microdown-BookTester/MicReferenceChecker.class.st index 4dee2276..96d725aa 100644 --- a/src/Microdown-BookTester/MicReferenceChecker.class.st +++ b/src/Microdown-BookTester/MicReferenceChecker.class.st @@ -25,7 +25,7 @@ Class { 'anchors', 'duplicatedAnchors', 'results', - 'fileSystem' + 'rootDirectory' ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' @@ -90,11 +90,11 @@ MicReferenceChecker >> checkProject: aFileReference [ mainMic := Microdown parseFile: aFileReference. collector := MicFileCollector new. collector - fileSystem: fileSystem; + rootDirectory: rootDirectory; visit: mainMic. self handleUndefinedFilesFrom: collector. listOfFiles := collector visitedDocumentFiles collect: [ :file | - fileSystem referenceTo: file ]. + rootDirectory resolve: file ]. self checkList: listOfFiles ] @@ -119,7 +119,7 @@ MicReferenceChecker >> duplicatedAnchors [ { #category : 'accessing' } MicReferenceChecker >> fileSystem: aFileSystem [ - fileSystem := aFileSystem + rootDirectory := aFileSystem ] { #category : 'visiting' } @@ -160,7 +160,7 @@ MicReferenceChecker >> initialize [ super initialize. - fileSystem := FileSystem disk. + rootDirectory := FileSystem workingDirectory. results := OrderedCollection new. references := OrderedCollection new. anchors := OrderedCollection new. @@ -203,6 +203,12 @@ MicReferenceChecker >> results [ ^ results ] +{ #category : 'accessing' } +MicReferenceChecker >> rootDirectory: aFileReferemce [ + + rootDirectory := aFileReferemce +] + { #category : 'internal' } MicReferenceChecker >> unknownAnchors [