forked from pharo-project/pharo
/
TemporaryVariableTest.class.st
93 lines (77 loc) · 2.66 KB
/
TemporaryVariableTest.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"
Tests for TemporaryVariable
"
Class {
#name : #TemporaryVariableTest,
#superclass : #TestCase,
#category : #'Slot-Tests-VariablesAndSlots'
}
{ #category : #tests }
TemporaryVariableTest >> testHasTemporaryVariablesBlock [
| block |
block := [ | b | b := 2. b +2 ].
self assert: (block hasTemporaryVariableNamed: #b)
]
{ #category : #tests }
TemporaryVariableTest >> testHasTemporaryVariablesMethod [
| method |
method := self class >> #testTemporaryVariablesMethod.
self assert: (method hasTemporaryVariableNamed: #method)
]
{ #category : #tests }
TemporaryVariableTest >> testIsReferenced [
| method notReferenced |
"The temp notReferenced is not used as we test exactly that here"
method := self class >> #testIsReferenced.
self assert: method temporaryVariables first isReferenced.
self deny: method temporaryVariables second isReferenced.
]
{ #category : #properties }
TemporaryVariableTest >> testPropertyAtPut [
| testValue temp |
testValue := Date today.
temp := thisContext temporaryVariableNamed: #testValue.
temp propertyAt: #testKeySelector put: testValue.
self
assert: (temp propertyAt: #testKeySelector)
equals: testValue.
temp removeProperty: #testKeySelector.
self assert: temp properties isNil
]
{ #category : #tests }
TemporaryVariableTest >> testReadNodes [
| method |
"On the level of CompiledMethod, args include temps. This needs to be fixed"
method := OrderedCollection >> #do:.
self assert: (method temporaryVariableNamed: #aBlock) astNodes notEmpty
]
{ #category : #tests }
TemporaryVariableTest >> testReadTemporaryVariablesMethod [
| tempVar |
tempVar := thisContext temporaryVariableNamed: #tempVar.
self assert: (tempVar readInContext: thisContext) class equals: TemporaryVariable
]
{ #category : #tests }
TemporaryVariableTest >> testTemporaryVariablesBlock [
| block |
block := [ | b | b +2 ].
self assert: block temporaryVariables first name equals: #b
]
{ #category : #tests }
TemporaryVariableTest >> testTemporaryVariablesMethod [
| method |
method := self class >> #testTemporaryVariablesMethod.
self assert: method temporaryVariables first name equals: #method.
"On the level of CompiledMethod, args include temps. This needs to be fixed"
method := OrderedCollection >> #do:.
self assert: method temporaryVariables first name equals: #aBlock.
self assert: (method hasTemporaryVariableNamed: #aBlock).
self assert: (method temporaryVariableNamed: #aBlock) class equals: ArgumentVariable.
]
{ #category : #tests }
TemporaryVariableTest >> testWriteTemporaryVariablesMethod [
| tempVar |
tempVar := thisContext temporaryVariableNamed: #tempVar.
tempVar write: 5 inContext: thisContext.
self assert: tempVar equals: 5
]