-
Notifications
You must be signed in to change notification settings - Fork 44
Feature/vocabulary #1012
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/vocabulary #1012
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 0742977
Add MicCheckerEngine with configureFrom: and checkerName for generic …
Fanirindrainy 9b43c98
Refactor MicCheckerEngine: use class-side checkerName and add collect…
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
78 changes: 78 additions & 0 deletions
78
src/Microdown-BookTester-Tests/MiCheckerEngineTest.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,78 @@ | ||
| Class { | ||
| #name : 'MiCheckerEngineTest', | ||
| #superclass : 'TestCase', | ||
| #instVars : [ | ||
| 'fileSystem', | ||
| 'engine', | ||
| 'file' | ||
| ], | ||
| #category : 'Microdown-BookTester-Tests', | ||
| #package : 'Microdown-BookTester-Tests' | ||
| } | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> generateFilesystemExample [ | ||
| file := fileSystem workingDirectory / 'test.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: 'The colour of the sky is blue. | ||
| ## writing books in pharo' | ||
| ]. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> setUp [ | ||
| super setUp. | ||
|
|
||
| fileSystem := FileSystem memory. | ||
| engine := MicCheckerEngine new. | ||
| self generateFilesystemExample. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> testEngineDetectsHeaderMistake [ | ||
| | config results | | ||
| config := OrderedDictionary new. | ||
| config at: 'HeaderCapitalization' put: 'uppercase'. | ||
| results := engine runOn: file withConfiguration: config. | ||
| self deny: results isEmpty. | ||
| self assert: results size equals: 3. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> testEngineDetectsVocabularyMistake [ | ||
| | config results | | ||
| config := OrderedDictionary new. | ||
| config at: 'Vocabulary' put: { ('colour' -> 'color') }. | ||
| results := engine runOn: file withConfiguration: config. | ||
| self deny: results isEmpty. | ||
| self assert: results size equals: 1. | ||
| self assert: (results first explanation includesSubstring: 'colour'). | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> testEngineRunsMultipleCheckers [ | ||
| | config results | | ||
| config := OrderedDictionary new. | ||
| config at: 'Vocabulary' put: { ('colour' -> 'color') }. | ||
| config at: 'HeaderCapitalization' put: 'uppercase'. | ||
| results := engine runOn: file withConfiguration: config. | ||
| self deny: results isEmpty. | ||
| self assert: results size > 1. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> testEngineWithEmptyConfiguration [ | ||
| | config results | | ||
| config := OrderedDictionary new. | ||
| results := engine runOn: file withConfiguration: config. | ||
| self assert: results isEmpty. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MiCheckerEngineTest >> testEngineWithUnknownChecker [ | ||
| | config results | | ||
| config := OrderedDictionary new. | ||
| config at: 'UnknownChecker' put: nil. | ||
| results := engine runOn: file withConfiguration: config. | ||
| self assert: results isEmpty. | ||
| ] | ||
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
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,52 @@ | ||
| " | ||
| I am a generic engine that reads a configuration dictionary and instantiates, configures and runs the appropriate checkers. | ||
| I discover all available checkers by looking at all subclasses of MicChecker that respond to #checkerName. | ||
|
|
||
| Usage example: | ||
| | engine config reslts | | ||
| config := OrderedDictionary new. | ||
| config at: 'Vocabulary' put: { ('colour' -> 'color') }. | ||
| config at: 'HeaderCapitalization' put: 'uppercase'. | ||
| config at: 'EnglishTypographic' put:nil. | ||
| engine := MicCheckerEngine new. | ||
| results := engine runOn: 'myFile.md' asFileReference withConfiguration: config. | ||
| results do: [ :r | Transcript showCr: r explanation ]. | ||
| " | ||
| Class { | ||
| #name : 'MicCheckerEngine', | ||
| #superclass : 'Object', | ||
| #category : 'Microdown-BookTester-Core', | ||
| #package : 'Microdown-BookTester', | ||
| #tag : 'Core' | ||
| } | ||
|
|
||
| { #category : 'as yet unclassified' } | ||
| MicCheckerEngine >> checkersFromConfiguration: aConfiguration [ | ||
| | availableCheckers activeCheckers | | ||
| availableCheckers := Dictionary new. | ||
| MicChecker allSubclasses do: [ :aClass | | ||
| availableCheckers at: aClass checkerName put: aClass ]. | ||
| activeCheckers := OrderedCollection new. | ||
| aConfiguration keysAndValuesDo: [ :key :value | | ||
| | checkerClass checker | | ||
| checkerClass := availableCheckers at: key ifAbsent: [ nil ]. | ||
| checkerClass ifNotNil: [ | ||
| checker := checkerClass new. | ||
| checker configureFrom: value. | ||
| activeCheckers add: checker | ||
| ] | ||
| ]. | ||
| ^ activeCheckers | ||
| ] | ||
|
|
||
| { #category : 'as yet unclassified' } | ||
| MicCheckerEngine >> runOn: aFileReference withConfiguration: aConfiguration [ | ||
| | activeCheckers results | | ||
| activeCheckers := self checkersFromConfiguration: aConfiguration. | ||
| results := OrderedCollection new. | ||
| activeCheckers do: [ :checker | | ||
| checker checkProject: aFileReference. | ||
| results addAll: checker results | ||
| ]. | ||
| ^ results | ||
| ] |
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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -9,6 +9,11 @@ Class { | |
| #tag : 'Vocabulary' | ||
| } | ||
|
|
||
| { #category : 'as yet unclassified' } | ||
| MicVocabularyChecker class >> checkerName [ | ||
| ^ 'Vocabulary' | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicVocabularyChecker >> checkText: aMicText [ | ||
|
|
||
|
|
@@ -21,6 +26,16 @@ MicVocabularyChecker >> checkText: aMicText [ | |
| patternPair: patternPair) ] ] | ||
| ] | ||
|
|
||
| { #category : 'as yet unclassified' } | ||
| MicVocabularyChecker >> configureFrom: aConfiguration [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be should check that we get an collection and not a boolean
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| aConfiguration isCollection ifTrue: [ self pairs: aConfiguration ] | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicVocabularyChecker >> pairs [ | ||
| ^ patternPairs | ||
| ] | ||
|
|
||
| { #category : 'visiting - inline elements' } | ||
| MicVocabularyChecker >> pairs: aCollectionOfPairs [ | ||
|
|
||
|
|
||
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.
Yes this is good to check that wrong input in checker name.