-
Notifications
You must be signed in to change notification settings - Fork 46
Add new checker : MicFigureCaption #1070
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
Open
AntoineUsal
wants to merge
10
commits into
pillar-markup:dev
Choose a base branch
from
AntoineUsal:checker
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e69277b
Add new checker : MicFigureCaption
AntoineUsal 3456057
Missing some tests
AntoineUsal c839fab
upgrade checker MicFigure
AntoineUsal fc7934c
Some changes for MicFigureCaption
AntoineUsal e39a590
Fix git error
AntoineUsal 020acab
add 2 tests
AntoineUsal 377e347
remove
AntoineUsal 3ff3c96
Merge 50bc9147afd7338780792441e8adc34f5bacab29
AntoineUsal 4c16e88
Change duplicate methods
AntoineUsal a46af2e
update config
AntoineUsal 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
109 changes: 109 additions & 0 deletions
109
src/Microdown-BookTester/MicFigureCaptionChecker.class.st
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,109 @@ | ||
| Class { | ||
| #name : 'MicFigureCaptionChecker', | ||
| #superclass : 'MicChecker', | ||
| #instVars : [ | ||
| 'checkFigure', | ||
| 'checkCode', | ||
| 'checkMath' | ||
| ], | ||
| #category : 'Microdown-BookTester', | ||
| #package : 'Microdown-BookTester' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkCaptionOf: aBlock [ | ||
| (self hasCorrectCaption: aBlock caption) ifFalse: [ | ||
| self results add: MicMissingFigureCaptionResult new ] | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkCode [ | ||
|
|
||
| ^ checkCode | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkCode: anObject [ | ||
|
|
||
| checkCode := anObject | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkFigure [ | ||
|
|
||
| ^ checkFigure | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkFigure: anObject [ | ||
|
|
||
| checkFigure := anObject | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkMath [ | ||
|
|
||
| ^ checkMath | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicFigureCaptionChecker >> checkMath: anObject [ | ||
|
|
||
| checkMath := anObject | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> checkMissingCaptionIn: aBlock text: captionText [ | ||
| (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ | ||
| self results add: (MicMissingFigureCaptionResult new | ||
| figure: aBlock; | ||
| yourself) ] | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> configureFrom: aDictionary [ | ||
| super configureFrom: aDictionary. | ||
| aDictionary at: 'checkOnly' ifPresent: [ :list | | ||
| self checkCode: false. | ||
| self checkFigure: false. | ||
| self checkMath: false. | ||
| (list includes: 'code') ifTrue: [ self checkCode: true ]. | ||
| (list includes: 'figure') ifTrue: [ self checkFigure: true ]. | ||
| (list includes: 'math') ifTrue: [ self checkMath: true ] ] | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> explanationForConfiguration [ | ||
| ^ 'I check that figures, math environments and code blocks have a valid and non-empty caption.' | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> hasCorrectCaption: aCaptionText [ | ||
| ^ aCaptionText isNotEmpty and: [ aCaptionText anySatisfy: #isAlphaNumeric ] | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> initialize [ | ||
| super initialize. | ||
| self checkCode: true. | ||
| self checkFigure: true. | ||
| self checkMath: true. | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> visitCode: aCode [ | ||
| self checkCode ifTrue: [ self checkCaptionOf: aCode ]. | ||
| ^ super visitCode: aCode | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> visitFigure: aFigure [ | ||
| self checkFigure ifTrue: [ self checkCaptionOf: aFigure ]. | ||
| ^ super visitFigure: aFigure | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicFigureCaptionChecker >> visitMath: aMath [ | ||
| self checkMath ifTrue: [ self checkCaptionOf: aMath ]. | ||
| ^ super visitMath: aMath | ||
| ] | ||
119 changes: 119 additions & 0 deletions
119
src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st
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,119 @@ | ||
| Class { | ||
| #name : 'MicFigureCaptionCheckerTest', | ||
| #superclass : 'TestCase', | ||
| #instVars : [ | ||
| 'results' | ||
| ], | ||
| #category : 'Microdown-BookTester', | ||
| #package : 'Microdown-BookTester' | ||
| } | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testCaptionIsEmpty [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'test.md'. | ||
| mdFile writeStreamDo: [ :stream | stream nextPutAll: '' ]. | ||
|
|
||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results size equals: 1. | ||
| self assert: visitor results first class name equals: #MicMissingFigureCaptionResult. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testCaptionIsOnlyPunctuationAndSpaces [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'test.md'. | ||
| mdFile writeStreamDo: [ :stream | stream nextPutAll: '' ]. | ||
|
|
||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results size equals: 1. | ||
| self assert: visitor results first class name equals: #MicMissingFigureCaptionResult. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testCaptionIsOnlySpaces [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'test.md'. | ||
| mdFile writeStreamDo: [ :stream | stream nextPutAll: '' ]. | ||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results size equals: 1. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testCaptionIsValid [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'test.md'. | ||
| mdFile writeStreamDo: [ :stream | stream nextPutAll: '' ]. | ||
|
|
||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results isEmpty. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'bogusCaption.md'. | ||
| mdFile writeStreamDo: [ :stream | | ||
| stream nextPutAll: '```smalltalk&caption= '; cr. | ||
| stream nextPutAll: '1 + 1'; cr. | ||
| stream nextPutAll: '```' ]. | ||
|
|
||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results size equals: 1. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testConfigureFromCheckOnly [ | ||
| | checker config | | ||
| checker := MicFigureCaptionChecker new. | ||
|
|
||
| self assert: checker checkCode. | ||
| self assert: checker checkFigure. | ||
| self assert: checker checkMath. | ||
|
|
||
| config := Dictionary new. | ||
| config at: 'checkOnly' put: #('code' 'math'). | ||
|
|
||
| checker configureFrom: config. | ||
|
|
||
| self assert: checker checkCode. | ||
| self assert: checker checkMath. | ||
| self deny: checker checkFigure. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ | ||
| | visitor mdFile mem | | ||
| mem := FileSystem memory root. | ||
| mdFile := mem / 'emptyCaption.md'. | ||
| mdFile writeStreamDo: [ :stream | | ||
| stream nextPutAll: '$$&caption='; cr. | ||
| stream nextPutAll: 'V = \frac{4}{3}\pi r^3'; cr. | ||
| stream nextPutAll: '$$' ]. | ||
|
|
||
| visitor := MicFigureCaptionChecker new. | ||
| visitor rootDirectory: mem. | ||
| visitor checkProject: mdFile. | ||
|
|
||
| self assert: visitor results size equals: 1. | ||
| ] |
19 changes: 19 additions & 0 deletions
19
src/Microdown-BookTester/MicMissingFigureCaptionResult.class.st
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,19 @@ | ||
| Class { | ||
| #name : 'MicMissingFigureCaptionResult', | ||
| #superclass : 'MicResult', | ||
| #instVars : [ | ||
| 'figure' | ||
| ], | ||
| #category : 'Microdown-BookTester', | ||
| #package : 'Microdown-BookTester' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| MicMissingFigureCaptionResult >> figure [ | ||
| ^ figure | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicMissingFigureCaptionResult >> figure: aFigure [ | ||
| figure := aFigure | ||
| ] |
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
Oops, something went wrong.
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.
Since we should check the caption for code, figure, equation can you create an helper method to define the logic of the test hasCorrectCaption: in a single place?