|
| 1 | +Class { |
| 2 | + #name : 'MicLastPeriodInCodeCheckerTest', |
| 3 | + #superclass : 'TestCase', |
| 4 | + #instVars : [ |
| 5 | + 'fileSystem', |
| 6 | + 'checker' |
| 7 | + ], |
| 8 | + #category : 'Microdown-Rules-CodeLastPeriod', |
| 9 | + #package : 'Microdown-Rules', |
| 10 | + #tag : 'CodeLastPeriod' |
| 11 | +} |
| 12 | + |
| 13 | +{ #category : 'running' } |
| 14 | +MicLastPeriodInCodeCheckerTest >> generateFilesystemExample [ |
| 15 | + |
| 16 | + | file | |
| 17 | + file := fileSystem workingDirectory / 'codeEndingWithPeriod.md'. |
| 18 | + file writeStreamDo: [ :stream | |
| 19 | + stream nextPutAll: ' |
| 20 | +
|
| 21 | +Authors may want to detect useless period as in the following code snippet |
| 22 | +
|
| 23 | +``` |
| 24 | +setX: xInt setY: yInt |
| 25 | +
|
| 26 | + x := xInt. |
| 27 | + y := yInt. |
| 28 | +``` |
| 29 | +' ]. |
| 30 | + |
| 31 | + file := fileSystem workingDirectory / 'codeNotEndingWithPeriod.md'. |
| 32 | + file writeStreamDo: [ :stream | |
| 33 | + stream nextPutAll: ' |
| 34 | +
|
| 35 | +Here the code does not a useless period. |
| 36 | +``` |
| 37 | +setX: xInt setY: yInt |
| 38 | +
|
| 39 | + x := xInt. |
| 40 | + y := yInt |
| 41 | +``` |
| 42 | +' ] |
| 43 | +] |
| 44 | + |
| 45 | +{ #category : 'running' } |
| 46 | +MicLastPeriodInCodeCheckerTest >> setUp [ |
| 47 | + |
| 48 | + super setUp. |
| 49 | + fileSystem := FileSystem memory. |
| 50 | + self generateFilesystemExample. |
| 51 | + |
| 52 | + checker := MicLastPeriodInCodeChecker new. |
| 53 | + |
| 54 | +] |
| 55 | + |
| 56 | +{ #category : 'tests - missing period' } |
| 57 | +MicLastPeriodInCodeCheckerTest >> testCheckerChecksCorrectlyMissingExtraPeriod [ |
| 58 | + "may be the author wants all the code to finish with an extra period. |
| 59 | + so we configure the checker to do so." |
| 60 | + |
| 61 | + checker identifyMissingLastPeriod. |
| 62 | + checker checkProject: fileSystem / 'codeEndingWithPeriod.md'. |
| 63 | + self assert: checker isOkay. |
| 64 | + |
| 65 | +] |
| 66 | + |
| 67 | +{ #category : 'tests - extra period' } |
| 68 | +MicLastPeriodInCodeCheckerTest >> testCheckerChecksCorrectlyNoExtraPeriod [ |
| 69 | + |
| 70 | + checker identifyExtraLastPeriod. |
| 71 | + checker checkProject: fileSystem / 'codeNotEndingWithPeriod.md'. |
| 72 | + self assert: checker isOkay |
| 73 | +] |
| 74 | + |
| 75 | +{ #category : 'tests - extra period' } |
| 76 | +MicLastPeriodInCodeCheckerTest >> testCheckerIdentifyCorrectlyExtraPeriod [ |
| 77 | + |
| 78 | + checker identifyExtraLastPeriod. |
| 79 | + checker checkProject: fileSystem / 'codeEndingWithPeriod.md'. |
| 80 | + self deny: checker isOkay. |
| 81 | + |
| 82 | + self assert: checker results first explanation equals: 'Text: "setX: xInt setY: yInt |
| 83 | +
|
| 84 | + x := xInt. |
| 85 | + y := yInt." in file/codeEndingWithPeriod.md contains a mistake: It should not be terminated with a period (.).' |
| 86 | +] |
| 87 | + |
| 88 | +{ #category : 'tests - missing period' } |
| 89 | +MicLastPeriodInCodeCheckerTest >> testCheckerIdentifyCorrectlyMissingExtraPeriod [ |
| 90 | + |
| 91 | + "may be the author wants all the code to finish with an extra period. |
| 92 | + so we configure the checker to do so." |
| 93 | + |
| 94 | + checker identifyMissingLastPeriod. |
| 95 | + checker checkProject: fileSystem / 'codeNotEndingWithPeriod.md'. |
| 96 | + self deny: checker isOkay. |
| 97 | + |
| 98 | + self |
| 99 | + assert: checker results first explanation |
| 100 | + equals: |
| 101 | + 'Text: "setX: xInt setY: yInt |
| 102 | +
|
| 103 | + x := xInt. |
| 104 | + y := yInt" in file/codeNotEndingWithPeriod.md contains a mistake: It should be terminated with a period (.).' |
| 105 | +] |
0 commit comments