Skip to content

Commit

Permalink
- This PR adds tests for RBGenericNodeVisitor
Browse files Browse the repository at this point in the history
- adds #visit:anySatisfy: and #visit:noneSatify: 
- move RBCommentNodeVisitorTest close to the other visitor tests
  • Loading branch information
MarcusDenker committed Dec 11, 2020
1 parent 768c3c6 commit c8fb8b1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AST-Core-Tests/RBCommentNodeVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUnit tests for RBCommentNodeVisitor
Class {
#name : #RBCommentNodeVisitorTest,
#superclass : #RBParseTreeTest,
#category : #'AST-Core-Tests-Nodes'
#category : #'AST-Core-Tests-Visitors'
}

{ #category : #tests }
Expand Down
50 changes: 50 additions & 0 deletions src/AST-Core-Tests/RBGenericNodeVisitorTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Class {
#name : #RBGenericNodeVisitorTest,
#superclass : #RBParseTreeTest,
#category : #'AST-Core-Tests-Visitors'
}

{ #category : #tests }
RBGenericNodeVisitorTest >> testVisitAnySatisfy [
| result tree |
tree := self parseExpression: 'Object new'.
result := RBGenericNodeVisitor visit: tree anySatisfy: [ :n | n isMessage ].
self assert: result.
result := RBGenericNodeVisitor visit: tree anySatisfy: [ :n | n isReturn ].
self deny: result
]

{ #category : #tests }
RBGenericNodeVisitorTest >> testVisitDetect [
| node tree |
tree := self parseExpression: 'Object new'.
node := RBGenericNodeVisitor visit: tree detect: [ :n | n isMessage ].
self assert: node isMessage
]

{ #category : #tests }
RBGenericNodeVisitorTest >> testVisitDetectIfNone [
| result tree |
tree := self parseExpression: 'Object new'.
result := RBGenericNodeVisitor visit: tree detect: [ :n | n isReturn ] ifNone: [ #none ].
self assert: result equals: #none
]

{ #category : #tests }
RBGenericNodeVisitorTest >> testVisitNoneSatisfy [
| result tree |
tree := self parseExpression: 'Object new'.
result := RBGenericNodeVisitor visit: tree noneSatisfy: [ :n | n isMessage ].
self deny: result.
result := RBGenericNodeVisitor visit: tree noneSatisfy: [ :n | n isReturn ].
self assert: result
]

{ #category : #tests }
RBGenericNodeVisitorTest >> testVisitSelect [
| result tree |
tree := self parseExpression: 'Object new'.
result := RBGenericNodeVisitor visit: tree select: [ :n | n isMessage ].
self assert: result size equals: 1.
self assert: result first selector equals: #new
]
16 changes: 16 additions & 0 deletions src/AST-Core/RBAbstractBlockVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Class {
#category : #'AST-Core-Visitors'
}

{ #category : #enumerating }
RBAbstractBlockVisitor class >> visit: aTree anySatisfy: aBlock [
self
visit: aTree
do: [ :node | (aBlock value: node) ifTrue: [ ^ true ] ].
^ false
]

{ #category : #enumerating }
RBAbstractBlockVisitor class >> visit: aTree detect: aBlock [

Expand All @@ -33,6 +41,14 @@ RBAbstractBlockVisitor class >> visit: aTree do: aBlock [
visitNode: aTree
]

{ #category : #enumerating }
RBAbstractBlockVisitor class >> visit: aTree noneSatisfy: aBlock [
self
visit: aTree
do: [ :node | (aBlock value: node) ifTrue: [ ^ false ] ].
^ true
]

{ #category : #enumerating }
RBAbstractBlockVisitor class >> visit: aTree select: aBlock [
| result |
Expand Down

0 comments on commit c8fb8b1

Please sign in to comment.