-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/General-Rules-Tests/ReAssignmentFormattingRuleTest.class.st
This file contains 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,47 @@ | ||
Class { | ||
#name : 'ReAssignmentFormattingRuleTest', | ||
#superclass : 'ReAbstractRuleTestCase', | ||
#category : 'General-Rules-Tests-Formatting', | ||
#package : 'General-Rules-Tests', | ||
#tag : 'Formatting' | ||
} | ||
|
||
{ #category : 'tests' } | ||
ReAssignmentFormattingRuleTest >> testRuleCase1 [ | ||
|
||
| critiques | | ||
|
||
self class compile: 'method | arg | arg:=1' classified: 'test-helper'. | ||
[ critiques := self myCritiquesOnMethod: self class >> #method. | ||
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
ReAssignmentFormattingRuleTest >> testRuleCase2 [ | ||
|
||
| critiques | | ||
|
||
self class compile: 'method | arg | arg:= 1' classified: 'test-helper'. | ||
[ critiques := self myCritiquesOnMethod: self class >> #method. | ||
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
ReAssignmentFormattingRuleTest >> testRuleCase3 [ | ||
|
||
| critiques | | ||
|
||
self class compile: 'method | arg | arg :=1' classified: 'test-helper'. | ||
[ critiques := self myCritiquesOnMethod: self class >> #method. | ||
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
ReAssignmentFormattingRuleTest >> testRuleNotViolated [ | ||
|
||
| critiques | | ||
|
||
self class compile: 'method | arg | arg := 1' classified: 'test-helper'. | ||
[ critiques := self myCritiquesOnMethod: self class >> #method. | ||
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] | ||
] |
This file contains 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,45 @@ | ||
" | ||
This rule verify if there is spaces when you make an assignement | ||
Prefer | ||
arg := 1 | ||
over | ||
arg:=1 | ||
" | ||
Class { | ||
#name : 'ReAssignmentFormattingRule', | ||
#superclass : 'ReNodeBasedRule', | ||
#category : 'General-Rules-Formatting', | ||
#package : 'General-Rules', | ||
#tag : 'Formatting' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
ReAssignmentFormattingRule class >> group [ | ||
|
||
^ 'Formatting' | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReAssignmentFormattingRule class >> rationale [ | ||
|
||
^ 'there should be an space between the temporary, ":=" and the assignment variable' | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReAssignmentFormattingRule class >> ruleName [ | ||
|
||
^ 'Assignment formatting' | ||
] | ||
|
||
{ #category : 'running' } | ||
ReAssignmentFormattingRule >> basicCheck: aNode [ | ||
|
||
| arg variable | | ||
|
||
aNode isAssignment ifFalse: [ ^ false ]. | ||
arg := aNode children first. | ||
variable := aNode children second. | ||
^ variable stop + 5 > arg start | ||
] |