-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1214 from MarcusDenker/21726-add-a-first-version-…
…of-evaluate-and-evaluateInContext-to-RBValueNode-and-use-it-in-RBBlockPatternNode 21726-add-a-first-version-of-evaluate-and-evaluateInContext-to-RBValueNode-and-use-it-in-RBBlockPatternNode
- Loading branch information
Showing
3 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
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
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
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,49 @@ | ||
" | ||
I am testing AST evaluation | ||
" | ||
Class { | ||
#name : #ASTEvaluationTest, | ||
#superclass : #TestCase, | ||
#category : #'AST-Tests-Core' | ||
} | ||
|
||
{ #category : #tests } | ||
ASTEvaluationTest >> testEvaluate [ | ||
self assert: (RBLiteralNode value: 5) evaluate equals: 5 | ||
] | ||
|
||
{ #category : #tests } | ||
ASTEvaluationTest >> testEvaluateForContext [ | ||
| varForTesting node | | ||
varForTesting := 4@5. | ||
|
||
"first we test if we can read the temp varForTesting" | ||
node := thisContext method variableNodes first. | ||
self assert: (node evaluateForContext: thisContext) equals: varForTesting. | ||
|
||
"lets check self, super" | ||
node := RBVariableNode named: 'self'. | ||
self assert: (node evaluateForContext: thisContext) equals: thisContext receiver. | ||
node := RBVariableNode named: 'super'. | ||
self assert: (node evaluateForContext: thisContext) equals: thisContext receiver. | ||
|
||
"thisContext is not the thisContext of this method though... it is the context of the evaluating doit" | ||
node := RBVariableNode named: 'thisContext'. | ||
self deny: (node evaluateForContext: thisContext) equals: thisContext. | ||
|
||
"reading ivars works, too" | ||
node := RBVariableNode named: 'testSelector'. | ||
self assert: (node evaluateForContext: thisContext) equals: #testEvaluateForContext. | ||
] | ||
|
||
{ #category : #tests } | ||
ASTEvaluationTest >> testEvaluateForReceiver [ | ||
| receiver node | | ||
receiver := 4@5. | ||
node := (receiver class>>#x) variableNodes first. | ||
self assert: (node evaluateForReceiver: receiver) equals: 4. | ||
node := RBVariableNode named: 'self'. | ||
self assert: (node evaluateForReceiver: receiver) equals: receiver. | ||
node := RBVariableNode named: 'super'. | ||
self assert: (node evaluateForReceiver: receiver) equals: receiver. | ||
] |