Skip to content
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

Add rules tests #16809

Open
wants to merge 5 commits into
base: Pharo13
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions src/General-Rules-Tests/ReAllAnyNoneSatisfyRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Class {
#name : 'ReAllAnyNoneSatisfyRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReAllAnyNoneSatisfyRuleTest >> testRuleNotViolated [

| critiques |
self class
compile: 'method

^ (OrderedCollection new) noneSatisfy: [ :each | each == 1 ]'
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReAllAnyNoneSatisfyRuleTest >> testRuleWithAllSatisfy [

| critiques |
self class
compile: 'method

(OrderedCollection new) do: [ :each | each == 1 ifFalse: [ ^ false ] ]. ^ true '
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReAllAnyNoneSatisfyRuleTest >> testRuleWithAnySatisfy [

| critiques |
self class
compile: 'method

(OrderedCollection new) do: [ :each | each == 1 ifTrue: [ ^ true ] ]. ^ false '
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReAllAnyNoneSatisfyRuleTest >> testRuleWithNoneSatisfy [

| critiques |
self class
compile: 'method

(OrderedCollection new) do: [ :each | each == 1 ifTrue: [ ^ false ] ]. ^ true '
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]
36 changes: 36 additions & 0 deletions src/General-Rules-Tests/ReBadMessageRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Class {
#name : 'ReBadMessageRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#instVars : [
'classFactory'
],
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'running' }
ReBadMessageRuleTest >> setUp [
super setUp.
classFactory := ClassFactoryForTestCase new.
]

{ #category : 'running' }
ReBadMessageRuleTest >> tearDown [

classFactory cleanUp.
super tearDown
]

{ #category : 'tests' }
ReBadMessageRuleTest >> testRule [

| critiques aClass|
aClass := classFactory make: [ :aBuilder |
aBuilder
tag: 'aTag';
package: 'aPackage' ].
aClass class compile: 'method 1 isMemberOf: Integer' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: aClass class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (aClass class >> #method) removeFromSystem ]
]
25 changes: 25 additions & 0 deletions src/General-Rules-Tests/ReCascadedNextPutAllsRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class {
#name : 'ReCascadedNextPutAllsRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReCascadedNextPutAllsRuleTest >> testRule [

| critiques |
self class compile: 'printOn: aStream aStream nextPutAll: ''test'', ''1'' ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #printOn:.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #printOn:) removeFromSystem ]
]

{ #category : 'tests' }
ReCascadedNextPutAllsRuleTest >> testRuleNotViolated [

| critiques |
self class compile: 'printOn: aStream aStream nextPutAll: ''test''; nextPutAll: ''1'' ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #printOn:.
self assertEmpty: critiques ] ensure: [ (self class >> #printOn:) removeFromSystem ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : 'ReCollectionAtCollectionSizeRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReCollectionAtCollectionSizeRuleTest >> testRule [

| critiques |
self class
compile:
'method | col | col := OrderedCollection. col add: 1; add: 2; add: 3. ^ col at: col size'
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReCollectionAtCollectionSizeRuleTest >> testRuleNotViolated [

| critiques |
self class
compile:
'method | col | col := OrderedCollection. col add: 1; add: 2; add: 3. ^ col last '
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Class {
#name : 'ReCollectionMessagesToExternalObjectRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#instVars : [
'classFactory'
],
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'running' }
ReCollectionMessagesToExternalObjectRuleTest >> setUp [
super setUp.
classFactory := ClassFactoryForTestCase new
]

{ #category : 'running' }
ReCollectionMessagesToExternalObjectRuleTest >> tearDown [

classFactory cleanUp.
super tearDown
]

{ #category : 'tests' }
ReCollectionMessagesToExternalObjectRuleTest >> testRule [

| critiques aClass |
aClass := classFactory make: [ :aBuilder |
aBuilder
name: 'ClassToSupp' ;
slots: {#aCol };
tag: 'aTag';
package: 'aPackage'
].
aClass class compile: 'initialize super initialize. aCol := OrderedCollection new.' classified: 'initialization'.
aClass compile: 'aCol ^ aCol' classified: 'accessing'.
self class compile: 'method | aClass | aClass := ClassToSupp new. aClass aCol add: 1; add: 2' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 2 ] ensure: [ (self class >> #method) removeFromSystem ]

]

{ #category : 'tests' }
ReCollectionMessagesToExternalObjectRuleTest >> testRuleNotViolated [

| critiques aClass |
aClass := classFactory make: [ :aBuilder |
aBuilder
name: 'ClassForTest';
slots: { #aCol };
tag: 'aTag';
package: 'aPackage' ].
aClass class compile: 'adding aCol add: 1' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: aClass class >> #adding.
self assertEmpty: critiques ] ensure: [ aClass class >> #adding ]


]
34 changes: 34 additions & 0 deletions src/General-Rules-Tests/ReCollectionProtocolRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : 'ReCollectionProtocolRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReCollectionProtocolRuleTest >> testRule [

| critiques |
self class compile: 'method | set col | set := #(1 2 3). col := OrderedCollection new. set do: [ :number | col add: number ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReCollectionProtocolRuleTest >> testRuleNotViolatedWithCollect [

| critiques |
self class compile: 'method | set col | set := #(1 2 3). col := set collect: [ :number | number ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReCollectionProtocolRuleTest >> testRuleNotViolatedWithSelect [

| critiques |
self class compile: 'method | set col | set := #(1 2 3). col := set select: [ :number | number%2 ~= 0] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
43 changes: 43 additions & 0 deletions src/General-Rules-Tests/ReDetectContainsRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Class {
#name : 'ReDetectContainsRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReDetectContainsRuleTest >> testRule1 [

| critiques |
self class compile: 'method | col | col := OrderedCollection new. col do: [ :elem | elem > 1 ifTrue: [ ^ elem ] ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReDetectContainsRuleTest >> testRule2 [

| critiques |
self class compile: 'method | col | col := OrderedCollection new. col do: [ :elem | elem > 1 ifFalse: [ ^ true ] ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReDetectContainsRuleTest >> testRuleNotViolatedWithContains [

| critiques |
self class compile: 'method | col | col := OrderedCollection new. col contains: 1 ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReDetectContainsRuleTest >> testRuleNotViolatedWithDetect [

| critiques |
self class compile: 'method | col | col := OrderedCollection new. col detect: [ :elem | elem > 1 ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
43 changes: 43 additions & 0 deletions src/General-Rules-Tests/ReDetectIfNoneRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Class {
#name : 'ReDetectIfNoneRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReDetectIfNoneRuleTest >> testRuleNotViolated [

| critiques |
self class
compile:
'method | temp | temp := OrderedCollection new. temp anySatisfy: [ :each | each > 1 ]'
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReDetectIfNoneRuleTest >> testRuleWithContains [

| critiques |
self class
compile:
'method | temp | temp := OrderedCollection new. temp contains: [ :each | each > 1 ] '
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReDetectIfNoneRuleTest >> testRuleWithDetect [

| critiques |
self class
compile:
'method | temp | temp := OrderedCollection new. (temp detect: [ :each | each > 1 ] ifNone: [ nil ] ) isNil'
classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]
25 changes: 25 additions & 0 deletions src/General-Rules-Tests/ReEqualNilRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class {
#name : 'ReEqualNilRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReEqualNilRuleTest >> testRule [

| critiques |
self class compile: 'method | arg | ^ arg = nil' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReEqualNilRuleTest >> testRuleNotViolated [

| critiques |
self class compile: 'method | arg | ^ arg isNil' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
25 changes: 25 additions & 0 deletions src/General-Rules-Tests/ReGuardClauseRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class {
#name : 'ReGuardClauseRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Coding Idiom Violation',
#package : 'General-Rules-Tests',
#tag : 'Coding Idiom Violation'
}

{ #category : 'tests' }
ReGuardClauseRuleTest >> testRule [

| critiques |
self class compile: 'method | arg | arg := 1. arg > 2 ifTrue: [ 1. 1. ] ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReGuardClauseRuleTest >> testRuleNotViolated [

| critiques |
self class compile: 'method | arg | arg := 1. arg > 2 ifFalse: [ ^ self ]. 1. 1. ' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
Loading