Skip to content

Commit c8eaf78

Browse files
committed
A first green test for header validation
- created a small report hierarchy - introduced micRule as root for the rules.
1 parent cca05c9 commit c8eaf78

12 files changed

+191
-65
lines changed

src/Microdown-Rules/Ideas.class.st

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ and not
118118
Class {
119119
#name : 'Ideas',
120120
#superclass : 'Object',
121-
#category : 'Microdown-Rules',
122-
#package : 'Microdown-Rules'
121+
#category : 'Microdown-Rules-Others',
122+
#package : 'Microdown-Rules',
123+
#tag : 'Others'
123124
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Class {
2+
#name : 'MicFirstElementOfHeaderIsNotCapitalizedReport',
3+
#superclass : 'MicReport',
4+
#category : 'Microdown-Rules-Capitalization',
5+
#package : 'Microdown-Rules',
6+
#tag : 'Capitalization'
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class {
2+
#name : 'MicHeaderCapitalizationRule',
3+
#superclass : 'MicRule',
4+
#instVars : [
5+
'shouldVerifyHeadersAreNotCapitilized'
6+
],
7+
#category : 'Microdown-Rules-Capitalization',
8+
#package : 'Microdown-Rules',
9+
#tag : 'Capitalization'
10+
}
11+
12+
{ #category : 'asserting' }
13+
MicHeaderCapitalizationRule >> shouldVerifyHeadersAreNotCapitilized [
14+
15+
shouldVerifyHeadersAreNotCapitilized := true
16+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Class {
2+
#name : 'MicHeaderCapitalizationTest',
3+
#superclass : 'TestCase',
4+
#category : 'Microdown-Rules-Capitalization',
5+
#package : 'Microdown-Rules',
6+
#tag : 'Capitalization'
7+
}
8+
9+
{ #category : 'tests' }
10+
MicHeaderCapitalizationTest >> testHeaderWronglyStartWithLowercase [
11+
12+
| r text checker error |
13+
r := MicHeaderCapitalizationRule new.
14+
r name: 'Header Capitalization'.
15+
r shouldVerifyHeadersAreNotCapitilized.
16+
17+
text := Microdown parse: '
18+
# about capitalisation of headers
19+
'.
20+
checker := MicRuleHeaderChecker new.
21+
checker visit: text.
22+
self
23+
assert: checker errors size
24+
equals: 1.
25+
error := checker errors first.
26+
self
27+
assert: error micElement text
28+
equals: 'about capitalisation of headers'
29+
]

src/Microdown-Rules/MicMisusedVocabularyRule.class.st

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Class {
22
#name : 'MicMisusedVocabularyRule',
33
#superclass : 'MicRule',
44
#instVars : [
5-
'name',
65
'pairs',
76
'matchingPatterns'
87
],
9-
#category : 'Microdown-Rules',
10-
#package : 'Microdown-Rules'
8+
#category : 'Microdown-Rules-Others',
9+
#package : 'Microdown-Rules',
10+
#tag : 'Others'
1111
}
1212

1313
{ #category : 'examples' }
@@ -41,11 +41,6 @@ MicMisusedVocabularyRule >> matchingPatterns [
4141
^ matchingPatterns ifNil: [ matchingPatterns := self computePatterns]
4242
]
4343

44-
{ #category : 'accessing' }
45-
MicMisusedVocabularyRule >> name: aString [
46-
name := aString
47-
]
48-
4944
{ #category : 'accessing' }
5045
MicMisusedVocabularyRule >> pairs [
5146
^ pairs
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Class {
2+
#name : 'MicReport',
3+
#superclass : 'Object',
4+
#instVars : [
5+
'file',
6+
'rule',
7+
'text'
8+
],
9+
#category : 'Microdown-Rules-Capitalization',
10+
#package : 'Microdown-Rules',
11+
#tag : 'Capitalization'
12+
}
13+
14+
{ #category : 'accessing' }
15+
MicReport >> inFile [
16+
17+
^ file
18+
]
19+
20+
{ #category : 'accessing' }
21+
MicReport >> inFile: aFileReference [
22+
file := aFileReference
23+
]
24+
25+
{ #category : 'as yet unclassified' }
26+
MicReport >> micElement [
27+
^ text
28+
]
29+
30+
{ #category : 'accessing' }
31+
MicReport >> micElement: aMicText [
32+
33+
text := aMicText
34+
]
35+
36+
{ #category : 'accessing' }
37+
MicReport >> rule: aRule [
38+
39+
rule := aRule
40+
]
41+
42+
{ #category : 'accessing' }
43+
MicReport >> text [
44+
45+
^ text
46+
]
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Class {
22
#name : 'MicRule',
33
#superclass : 'Object',
4-
#category : 'Microdown-Rules',
5-
#package : 'Microdown-Rules'
4+
#instVars : [
5+
'name'
6+
],
7+
#category : 'Microdown-Rules-Others',
8+
#package : 'Microdown-Rules',
9+
#tag : 'Others'
610
}
11+
12+
{ #category : 'accessing' }
13+
MicRule >> name: aString [
14+
name := aString
15+
]
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
Class {
2-
#name : 'MicRuleChecker',
2+
#name : 'MicRuleAllTextChecker',
33
#superclass : 'MicrodownVisitor',
44
#instVars : [
55
'rules',
66
'errors',
77
'patternPairs'
88
],
9-
#category : 'Microdown-Rules',
10-
#package : 'Microdown-Rules'
9+
#category : 'Microdown-Rules-Others',
10+
#package : 'Microdown-Rules',
11+
#tag : 'Others'
1112
}
1213

1314
{ #category : 'adding' }
14-
MicRuleChecker >> addRule: aRule [
15+
MicRuleAllTextChecker >> addRule: aRule [
1516
rules add: aRule.
1617
]
1718

1819
{ #category : 'as yet unclassified' }
19-
MicRuleChecker >> checkText: aMicText [
20+
MicRuleAllTextChecker >> checkText: aMicText [
2021

2122
| foundProblems |
2223
"#( *xxx* -> r . *x x* -> r)"
@@ -32,25 +33,25 @@ MicRuleChecker >> checkText: aMicText [
3233
]
3334

3435
{ #category : 'accessing' }
35-
MicRuleChecker >> errors [
36+
MicRuleAllTextChecker >> errors [
3637
^ errors
3738
]
3839

3940
{ #category : 'initialization' }
40-
MicRuleChecker >> initialize [
41+
MicRuleAllTextChecker >> initialize [
4142

4243
super initialize.
4344
rules := OrderedCollection new.
4445
errors := OrderedCollection new.
4546
]
4647

4748
{ #category : 'accessing' }
48-
MicRuleChecker >> patterns [
49+
MicRuleAllTextChecker >> patterns [
4950
^ patternPairs
5051
]
5152

5253
{ #category : 'visiting - inline elements' }
53-
MicRuleChecker >> prepareForChecking [
54+
MicRuleAllTextChecker >> prepareForChecking [
5455
"in the future we should have multiple rules and managed this better"
5556

5657
| r |
@@ -59,7 +60,7 @@ MicRuleChecker >> prepareForChecking [
5960
]
6061

6162
{ #category : 'visiting - inline elements' }
62-
MicRuleChecker >> visitText: aMicText [
63+
MicRuleAllTextChecker >> visitText: aMicText [
6364

6465
self checkText: aMicText
6566
]

src/Microdown-Rules/MicRuleCheckerTest.class.st

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Class {
55
'fileSystem',
66
'ck'
77
],
8-
#category : 'Microdown-Rules',
9-
#package : 'Microdown-Rules'
8+
#category : 'Microdown-Rules-Others',
9+
#package : 'Microdown-Rules',
10+
#tag : 'Others'
1011
}
1112

1213
{ #category : 'tests' }
@@ -40,7 +41,7 @@ MicRuleCheckerTest >> setUp [
4041
fileSystem := FileSystem memory.
4142
self generateFilesystemExample.
4243

43-
ck := MicRuleChecker new.
44+
ck := MicRuleAllTextChecker new.
4445
ck addRule: MicMisusedVocabularyRule sample.
4546
ck prepareForChecking.
4647
]
@@ -95,7 +96,7 @@ MicRuleCheckerTest >> testCheckerFindOneMistakeInParagraph [
9596
MicRuleCheckerTest >> testCheckerPrepare [
9697

9798
| ck r |
98-
ck := MicRuleChecker new.
99+
ck := MicRuleAllTextChecker new.
99100
r := MicMisusedVocabularyRule sample.
100101
ck addRule: MicMisusedVocabularyRule sample.
101102
ck prepareForChecking.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Class {
2+
#name : 'MicRuleHeaderChecker',
3+
#superclass : 'MicrodownVisitor',
4+
#instVars : [
5+
'rules',
6+
'errors'
7+
],
8+
#category : 'Microdown-Rules-Capitalization',
9+
#package : 'Microdown-Rules',
10+
#tag : 'Capitalization'
11+
}
12+
13+
{ #category : 'adding' }
14+
MicRuleHeaderChecker >> addRule: aRule [
15+
rules add: aRule.
16+
]
17+
18+
{ #category : 'as yet unclassified' }
19+
MicRuleHeaderChecker >> checkFirstWord: aCollection of: anElement [
20+
21+
aCollection first first isUppercase
22+
ifFalse: [
23+
errors add: (MicFirstElementOfHeaderIsNotCapitalizedReport new
24+
micElement: anElement;
25+
inFile: anElement fromFile).
26+
27+
]
28+
]
29+
30+
{ #category : 'accessing' }
31+
MicRuleHeaderChecker >> errors [
32+
^ errors
33+
]
34+
35+
{ #category : 'initialization' }
36+
MicRuleHeaderChecker >> initialize [
37+
38+
super initialize.
39+
rules := OrderedCollection new.
40+
errors := OrderedCollection new.
41+
]
42+
43+
{ #category : 'visiting - inline elements' }
44+
MicRuleHeaderChecker >> visitHeader: aMicHeader [
45+
46+
| words |
47+
words := aMicHeader text splitOn: Character space.
48+
self checkFirstWord: words of: aMicHeader.
49+
"self checkRest: words."
50+
51+
]

0 commit comments

Comments
 (0)