-
Notifications
You must be signed in to change notification settings - Fork 44
Feature/references #1006
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
Merged
Merged
Feature/references #1006
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e15492
first commit after cloning
Fanirindrainy 2134a3b
Revert "first commit after cloning "
Fanirindrainy 1546408
Add reference checker for Figure/Section/Table capitalisazation befor…
Fanirindrainy bcd08f4
Add class comment to MicReferencesChecker
Fanirindrainy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| Class { | ||
| #name : 'MicFigSectTableResult', | ||
| #superclass : 'MicAbstractResult', | ||
| #instVars : [ | ||
| 'detail' | ||
| ], | ||
| #category : 'Microdown-Rules-References', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'References' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigSectTableResult >> detail [ | ||
|
|
||
| ^ detail | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigSectTableResult >> detail: anObject [ | ||
|
|
||
| detail := anObject | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigSectTableResult >> explanation [ | ||
| ^ 'Text: "' , micElement bodyString | ||
| , '" in file' , fileReference fullName | ||
| , ' contains a mistake: [' | ||
| , detail | ||
| , '] should be capitalized as [' | ||
| , detail capitalized , '].' | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| " | ||
| I check that references to figures, sections and tables are correctly capitalized before an anchor. | ||
| In Microdown, references should be written as: | ||
| Figure *@figureExample@* | ||
| Section *@sectionExample@* | ||
| Table *@tableExample* | ||
|
|
||
| The following are incorrect and will be flagged: | ||
| figure *@figureExample@* (lowercase) | ||
| the figure *@figureExample@* (proceded by 'the') | ||
| section *@sectionExample@* (lowercase) | ||
| " | ||
| Class { | ||
| #name : 'MicReferencesChecker', | ||
| #superclass : 'MicChecker', | ||
| #category : 'Microdown-Rules-References', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'References' | ||
| } | ||
|
|
||
| { #category : 'visiting' } | ||
| MicReferencesChecker >> visitParagraph: aMicParagraph [ | ||
| | children | | ||
| children := aMicParagraph children. | ||
| 1 to: children size - 1 do: [ :index | | ||
| | child nextChild | | ||
| child := children at: index. | ||
| nextChild := children at: index + 1. | ||
| (nextChild isKindOf: MicAnchorReferenceBlock ) ifTrue: [ | ||
| (child isKindOf: MicTextBlock ) ifTrue: [ | ||
| | words lastWord foundThe | | ||
| words := child bodyString substrings. | ||
| words isEmpty ifFalse:[ | ||
| lastWord := words last. | ||
| foundThe := false. | ||
| "verify the figure/section/table" | ||
| #('figure' 'section' 'table') do: [ :ref | | ||
| (lastWord asLowercase = ref) ifTrue: [ | ||
| words size > 1 ifTrue: [ | ||
| | prevWord | | ||
| prevWord := words at: words size - 1. | ||
| (prevWord asLowercase = 'the') ifTrue: [ | ||
| foundThe := true. | ||
| results add: (MicFigSectTableResult new | ||
| micElement: child; | ||
| inFile: aMicParagraph fromFile; | ||
| detail: 'the ' , lastWord; | ||
| yourself | ||
| ) | ||
| ] | ||
| ] | ||
| ] | ||
|
|
||
| ]. | ||
| "check figure/section/table" | ||
| foundThe ifFalse: [ | ||
| #('figure' 'table' 'section') do: [ :ref | | ||
| (lastWord = ref) ifTrue: [ | ||
| results add: (MicFigSectTableResult new | ||
| micElement: child; | ||
| inFile: aMicParagraph fromFile; | ||
| detail: lastWord; | ||
| yourself | ||
| ) | ||
| ] | ||
| ] | ||
|
|
||
|
|
||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| Class { | ||
| #name : 'MicReferencesCheckerTest', | ||
| #superclass : 'TestCase', | ||
| #instVars : [ | ||
| 'fileSystem', | ||
| 'checker' | ||
| ], | ||
| #category : 'Microdown-Rules-References', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'References' | ||
| } | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> generateFilesystemExample [ | ||
| | file | | ||
| file := fileSystem workingDirectory / 'figureWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'figure *@figbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'tableWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'table *@tablab@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'sectionWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'section *@secbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'theFigureWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'the figure *@figbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'theSectionWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'the section *@seclab@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'theTableWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'the table *@tabbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'figureCorrect.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'Figure *@figbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'sectionCorrect.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'Section *@secbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'tableCorrect.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'Table *@tabbla@*' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'noAnchor.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'figure without anchor' | ||
| ]. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> setUp [ | ||
| super setUp. | ||
|
|
||
| fileSystem := FileSystem memory. | ||
| self generateFilesystemExample. | ||
| checker := MicReferencesChecker new. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testFigureCorrect [ | ||
| checker checkProject: fileSystem / 'figureCorrect.md'. | ||
| self assert: checker isOkay. | ||
|
|
||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testFigureExplanation [ | ||
| checker checkProject: fileSystem / 'figureWrong.md'. | ||
| self assert: checker results first explanation | ||
| equals: 'Text: "figure " in file/figureWrong.md contains a mistake: [figure] should be capitalized as [Figure].'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testFigureLowercaseDetected [ | ||
| checker checkProject: fileSystem / 'figureWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results size equals: 1. | ||
| self assert: checker results first detail equals: 'figure'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testSectionCorrect [ | ||
| checker checkProject: fileSystem / 'sectionCorrect.md'. | ||
| self assert: checker isOkay. | ||
|
|
||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testSectionLowercaseDetected [ | ||
| checker checkProject: fileSystem / 'sectionWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results size equals: 1. | ||
| self assert: checker results first detail equals: 'section'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTableCorrect [ | ||
| checker checkProject: fileSystem / 'tableCorrect.md'. | ||
| self assert: checker isOkay. | ||
|
|
||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTableLowercaseDetected [ | ||
| checker checkProject: fileSystem / 'tableWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results size equals: 1. | ||
| self assert: checker results first detail equals: 'table'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTextWithoutAnchor [ | ||
| checker checkProject: fileSystem / 'noAnchor.md'. | ||
| self assert: checker isOkay. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTheFigureDetected [ | ||
| checker checkProject: fileSystem / 'theFigureWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results first detail equals: 'the figure'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTheSectionDetected [ | ||
| checker checkProject: fileSystem / 'theSectionWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results first detail equals: 'the section'. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicReferencesCheckerTest >> testTheTableDetected [ | ||
| checker checkProject: fileSystem / 'theTableWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results first detail equals: 'the table'. | ||
|
|
||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a class comment that explains what this checker is about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add class comment for this checker.