Skip to content

Commit b83b622

Browse files
committed
Added test case for reflection.
1 parent 9a52191 commit b83b622

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

platform-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(BASE_FUNCTORS
1313
#"finalize.oz" "gc.oz"
1414
"state.oz" "thread.oz"
1515
"vm.oz"
16+
"reflection.oz"
1617
)
1718
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/base")
1819
foreach(FUNCTOR ${BASE_FUNCTORS})

platform-test/base/reflection.oz

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
%%% Copyright © 2014, Université catholique de Louvain
2+
%%% All rights reserved.
3+
%%%
4+
%%% Redistribution and use in source and binary forms, with or without
5+
%%% modification, are permitted provided that the following conditions are met:
6+
%%%
7+
%%% * Redistributions of source code must retain the above copyright notice,
8+
%%% this list of conditions and the following disclaimer.
9+
%%% * Redistributions in binary form must reproduce the above copyright notice,
10+
%%% this list of conditions and the following disclaimer in the documentation
11+
%%% and/or other materials provided with the distribution.
12+
%%%
13+
%%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
%%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
%%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17+
%%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
%%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
%%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
%%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
%%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
%%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23+
%%% POSSIBILITY OF SUCH DAMAGE.
24+
25+
functor
26+
27+
import
28+
Reflection at 'x-oz://boot/Reflection'
29+
BootName at 'x-oz://boot/Name'
30+
31+
export
32+
Return
33+
34+
define
35+
Return = reflection([
36+
become(
37+
keys: [reflection become]
38+
1: proc {$}
39+
P = {NewCell 1}
40+
R = {NewArray 0 1 _}
41+
Q = P
42+
in
43+
true = (P == Q)
44+
true = (P \= R)
45+
true = (Q \= R)
46+
true = {IsCell P}
47+
true = {IsCell Q}
48+
true = {IsArray R}
49+
{Reflection.become P R}
50+
true = (P == Q)
51+
true = (P == R)
52+
true = (Q == R)
53+
false = {IsCell P}
54+
false = {IsCell Q}
55+
true = {IsArray P}
56+
true = {IsArray Q}
57+
true = {IsArray R}
58+
end
59+
)
60+
61+
getStructuralBehavior(
62+
keys: [reflection getStructuralBehavior]
63+
1: proc {$}
64+
P
65+
class C from BaseObject end
66+
in
67+
for A#B in [
68+
value#1
69+
value#x
70+
value#unit
71+
value#true
72+
value#false
73+
value#1.5
74+
value#~0.3
75+
value#nil
76+
value#{VirtualString.toCompactString "12345"}
77+
value#{VirtualByteString.toCompactByteString [0 1 2 3 4]}
78+
value#{BootName.newUnique test}
79+
structural#"string"
80+
structural#[1 2 3 4]
81+
structural#(1#2)
82+
structural#(r(a:1 b:2))
83+
token#{NewCell 1}
84+
token#{NewArray 0 1 _}
85+
token#C
86+
token#{New C noop}
87+
token#{NewName}
88+
token#{NewLock}
89+
token#{NewPort _}
90+
token#proc {$} skip end
91+
token#{NewWeakDictionary _}
92+
token#{NewDictionary}
93+
token#{NewChunk x}
94+
variable#_
95+
variable#P
96+
variable#(!!P)
97+
] do
98+
A = {Reflection.getStructuralBehavior B}
99+
end
100+
end
101+
)
102+
103+
reflectiveVariable(
104+
keys: [reflection reflectiveVariable]
105+
1: proc {$}
106+
S = _
107+
V = {Reflection.newReflectiveVariable S}
108+
Q = V
109+
A B C
110+
in
111+
thread
112+
true = (Q == 5)
113+
end
114+
thread
115+
{Delay 100}
116+
V = 5
117+
true = (V == 5)
118+
end
119+
120+
variable = {Reflection.getStructuralBehavior V}
121+
122+
A|B = S
123+
markNeeded = A.1 % <- probably we don't need to do anything with `markNeeded`?
124+
A.2 = unit
125+
C|_ = B
126+
bind(5) = C.1
127+
C.2 = unit
128+
129+
variable = {Reflection.getStructuralBehavior V}
130+
{Reflection.bindReflectiveVariable V 5}
131+
value = {Reflection.getStructuralBehavior V}
132+
end
133+
)
134+
135+
reflectiveEntity(
136+
keys: [reflection reflectiveEntity]
137+
1: proc {$}
138+
S
139+
E = {Reflection.newReflectiveEntity S}
140+
G
141+
in
142+
thread
143+
123 = @E
144+
456 = {Get E 678}
145+
G = 789
146+
end
147+
148+
token = {Reflection.getStructuralBehavior E}
149+
150+
(isCell(true)#unit)|(access(123)#unit)|(arrayGet(678 456)#unit)|_ = S
151+
152+
{Wait G}
153+
789 = G
154+
end
155+
)
156+
157+
throwExceptionEntity(
158+
keys: [reflection throwExceptionEntity]
159+
1: proc {$}
160+
SE
161+
E = {Reflection.newReflectiveEntity SE}
162+
EException
163+
in
164+
thread
165+
try
166+
{Put E 1 2}
167+
EException = unit
168+
catch X then
169+
EException = X
170+
end
171+
end
172+
173+
(_#{Value.failed someException})|_ = SE
174+
true = (EException == someException)
175+
end
176+
)
177+
178+
throwExceptionVariable(
179+
keys: [reflection throwExceptionVariable]
180+
1: proc {$}
181+
SV
182+
V = {Reflection.newReflectiveVariable SV}
183+
VException
184+
ExceptionToRaise = {Exception.failure something}
185+
in
186+
thread
187+
try
188+
V = 4
189+
VException = unit
190+
catch X then
191+
VException = X
192+
end
193+
end
194+
195+
(_#{Value.failed ExceptionToRaise})|_ = SV
196+
true = (VException == ExceptionToRaise)
197+
end
198+
)
199+
])
200+
end

0 commit comments

Comments
 (0)