Skip to content
Merged
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
8 changes: 5 additions & 3 deletions src/Microdown-Rules/MicEnglishTypographyChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ MicEnglishTypographyChecker >> addResultFor: anElement message: aMessage [

{ #category : 'adding' }
MicEnglishTypographyChecker >> checkString: aString for: anElement [
| checks |
| checks cleanString |
aString ifNil: [ ^self ].
cleanString := aString copyReplaceAll: (String with: Character lf) with: ' '.
cleanString := cleanString copyReplaceAll: (String with: Character cr) with: ' '.
checks := {
' \:' -> 'There is a space before :'.
' \,' -> 'There is a space before ,'.
'\:[^ ]' -> 'There is no space after :'.
'\:[^ /]' -> 'There is no space after :'.
',[^ ]' -> 'There is no space after ,'.
' \;' -> 'There is a space before ;'.
'\;[^ ]' -> 'There is no space after ;'.
Expand All @@ -52,7 +54,7 @@ checks := {
message := pair value.

matcher := RxMatcher forString: pattern.
(matcher matchesIn: aString) notEmpty ifTrue: [
(matcher matchesIn: cleanString) notEmpty ifTrue: [
self addResultFor: anElement message: message
]
].
Expand Down
52 changes: 52 additions & 0 deletions src/Microdown-Rules/MicEnglishTypographyCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,25 @@ This is correct: example, test.' ].
```smalltalk
collection do: [:each | each printString' ].

file := fileSystem workingDirectory / 'urlHTTPS.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'See https://books.pharo.org for more.' ].

file := fileSystem workingDirectory / 'urlHTTP.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'Visit http://pharo.org for details.' ].

file := fileSystem workingDirectory / 'colonNewline.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'Here is a list: - item one' ].

file := fileSystem workingDirectory / 'commaNewline.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'First, second.' ].

file := fileSystem workingDirectory / 'semicolonNewline.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'First; second.' ].

]

Expand Down Expand Up @@ -80,6 +97,41 @@ MicEnglishTypographyCheckerTest >> testMonospaceIgnored [
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoFalsePositiveForColonNewline [

checker checkProject: fileSystem / 'colonNewline.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoFalsePositiveForCommaline [

checker checkProject: fileSystem / 'commaNewline.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoFalsePositiveForHTTPSURL [

checker checkProject: fileSystem / 'urlHTTPS.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoFalsePositiveForHTTPURL [

checker checkProject: fileSystem / 'urlHTTP.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoFalsePositiveForSemicolonNewline [

checker checkProject: fileSystem / 'semicolonNewline.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicEnglishTypographyCheckerTest >> testNoSpaceAfterColon [

Expand Down
Loading