/
ASTEvaluationTest.class.st
49 lines (42 loc) · 1.61 KB
/
ASTEvaluationTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"
I am testing AST evaluation
"
Class {
#name : #ASTEvaluationTest,
#superclass : #TestCase,
#category : #'AST-Core-Tests'
}
{ #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.
]