forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OCASTVariableTranslatorTest.class.st
129 lines (102 loc) · 3.68 KB
/
OCASTVariableTranslatorTest.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Class {
#name : #OCASTVariableTranslatorTest,
#superclass : #OCASTTranslatorTest,
#category : #'OpalCompiler-Tests-AST'
}
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignArgumentVariable [
self
should: [self compileSource: 'argument: anArgument
anArgument := 17'] raise: OCStoreIntoReadOnlyVariableError
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignClassVariable [
self assert: instance iVar equals: nil.
self testExample: #exampleClassVariableAssignment.
self assert: instance classVariable equals: 1
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignGlobalVariable [
globals add: (GlobalVariable key: #GlobalVariable value: nil).
self testSource: 'exampleGlobalVariableAssignment
GlobalVariable := 17'.
self assert: (globals at: #GlobalVariable) equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignInstanceVariable [
self assert: instance iVar equals: nil.
self testExample: #exampleInstanceVariableAssignment.
self assert: instance iVar equals: 1
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignSelfVariable [
self
should: [self compileSource: 'foo
self := 17'] raise: OCStoreIntoReservedVariableError
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignSuperVariable [
self
should: [self compileSource: 'foo
super := 17'] raise: OCStoreIntoReservedVariableError
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignTemporaryVariable [
self testExample: #exampleTemporaryVariableAssignment.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testAssignThisContextVariable [
self
should: [self compileSource: 'foo
thisContext := 17'] raise: OCStoreIntoReservedVariableError
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushArgumentVariable [
self testExample: #examplePushArgumentVariable: withArgument: 17.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushClassVariable [
instance classVariable: 17.
self testExample: #examplePushClassVariable.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushGlobalVariable [
globals add: (GlobalVariable key: #GlobalVariable value: 17).
self testSource: 'exampleGlobalVariableAssignment
self message: GlobalVariable'.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushInstanceVariable [
instance iVar: 17.
self testExample: #examplePushInstanceVariable.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushSelf [
self assert: instance result equals: nil.
self testExample: #exampleSelf.
self assert: instance result equals: instance
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushSuper [
self assert: instance result equals: nil.
self testExample: #exampleSuper.
self assert: instance result equals: instance
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushTemporaryVariable [
instance iVar: 17.
self testExample: #examplePushTemporaryVariable.
self assert: instance result equals: 17
]
{ #category : #'testing - variables' }
OCASTVariableTranslatorTest >> testPushThisContext [
method := self compileExample: #exampleThisContext.
self executeMethodOnInstance: method.
self assert: instance result isContext.
self assert: instance result method equals: method.
]