/
OCDoitTest.class.st
107 lines (87 loc) · 2.44 KB
/
OCDoitTest.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
Class {
#name : #OCDoitTest,
#superclass : #TestCase,
#instVars : [
'ivarForTesting'
],
#category : #'OpalCompiler-Tests-Misc'
}
{ #category : #binding }
OCDoitTest >> bindingOf: aSelector [
^(aSelector == #requestorVarForTesting)
ifTrue: [WorkspaceVariable key: aSelector value: 5 ]
ifFalse: [nil]
]
{ #category : #binding }
OCDoitTest >> hasBindingOf: aSelector [
^aSelector == #requestorVarForTesting
]
{ #category : #'interactive error protocol' }
OCDoitTest >> notify: aString at: anInteger in: aString3 [
"we ignore"
]
{ #category : #tests }
OCDoitTest >> testDoItContextReadGlobal [
"we can read a global from a doit when executing against a context"
| value |
value := OpalCompiler new
source: 'Object';
context: thisContext;
evaluate.
self assert: value equals: Object
]
{ #category : #tests }
OCDoitTest >> testDoItContextReadIvar [
| value method |
"we can read this ivar from a doit when executing against thisContext"
ivarForTesting := #someValue.
method := OpalCompiler new
source: 'ivarForTesting';
noPattern: true;
context: thisContext;
compileDoit.
value := method valueWithReceiver: self arguments: { thisContext }.
self assert: value equals: #someValue
]
{ #category : #tests }
OCDoitTest >> testDoItContextReadTemp [
| tempForTesting value |
"we can read this temp from a doit when executing against thisContext"
tempForTesting := #someValue.
value := OpalCompiler new
source: 'tempForTesting';
context: thisContext;
evaluate.
self assert: value equals: #someValue
]
{ #category : #tests }
OCDoitTest >> testDoItRequestorEvalError [
| value |
value := OpalCompiler new
requestor: self;
evaluate: '1('.
self assert: value isNil.
]
{ #category : #tests }
OCDoitTest >> testDoItRequestorReadRequestorVar [
| value |
"we can read a variable from a requestor"
value := OpalCompiler new
source: 'requestorVarForTesting';
noPattern: true;
requestor: self;
evaluate.
self assert: value equals: 5
]
{ #category : #tests }
OCDoitTest >> testDoitContextCheckClass [
"if we create a parse tree for a doit in a context, the class should be correctly set"
| ast |
ast := OpalCompiler new
source: 'tempForTesting';
noPattern: true;
context: thisContext;
parseDoIt.
"we expect that the class is set to the class of the context, which is self class"
self assert: ast methodClass equals: self class
]