comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/MethodGuardsWithArgumentsTest.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/MethodGuardsWithArgumentsTest.java@08aa0372dad4
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.dsl.test;
24
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*;
26
27 import org.junit.*;
28
29 import com.oracle.truffle.api.dsl.*;
30 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArguments0Factory;
31 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArguments1Factory;
32 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArgumentsDouble0Factory;
33 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArgumentsDouble1Factory;
34 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArgumentsDouble2Factory;
35 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArgumentsDouble3Factory;
36 import com.oracle.truffle.api.dsl.test.MethodGuardsWithArgumentsTestFactory.MArgumentsSingle2Factory;
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
39
40 public class MethodGuardsWithArgumentsTest {
41
42 @Test
43 public void testMArguments0() {
44 TestRootNode<MArguments0> root = createRoot(MArguments0Factory.getInstance());
45 Assert.assertEquals(42, executeWith(root));
46 }
47
48 abstract static class MArguments0 extends ValueNode {
49
50 static boolean guard() {
51 return true;
52 }
53
54 @Specialization(guards = "guard()")
55 int do1() {
56 return 42;
57 }
58 }
59
60 @Test
61 public void testMArguments1() {
62 TestRootNode<MArguments1> root = createRoot(MArguments1Factory.getInstance());
63 Assert.assertEquals(42, executeWith(root));
64 }
65
66 abstract static class MArguments1 extends ValueNode {
67
68 static boolean guard() {
69 return true;
70 }
71
72 @Specialization(guards = "guard()")
73 int do1() {
74 return 42;
75 }
76 }
77
78 @Test
79 public void testMArgumentsSingle0() {
80 TestRootNode<MArguments1> root = createRoot(MArguments1Factory.getInstance());
81 Assert.assertEquals(42, executeWith(root, 42));
82 }
83
84 @NodeChild("a")
85 abstract static class MArgumentsSingle0 extends ValueNode {
86
87 static boolean guard() {
88 return true;
89 }
90
91 @Specialization(guards = "guard()")
92 int do1(int a) {
93 return a;
94 }
95 }
96
97 @Test
98 public void testMArgumentsSingle1() {
99 TestRootNode<MArguments1> root = createRoot(MArguments1Factory.getInstance());
100 Assert.assertEquals(42, executeWith(root, 42));
101 }
102
103 @NodeChild("a")
104 abstract static class MArgumentsSingle1 extends ValueNode {
105
106 static boolean guard(int a) {
107 return a == 42;
108 }
109
110 @Specialization(guards = "guard(a)")
111 int do1(int a) {
112 return a;
113 }
114 }
115
116 @Test
117 public void testMArgumentsSingle2() {
118 TestRootNode<MArgumentsSingle2> root = createRoot(MArgumentsSingle2Factory.getInstance());
119 Assert.assertEquals(42, executeWith(root, 42));
120 }
121
122 @NodeChild("a")
123 abstract static class MArgumentsSingle2 extends ValueNode {
124
125 static boolean guard(int a1, int a2) {
126 return a1 == 42 && a2 == 42;
127 }
128
129 @Specialization(guards = "guard(a,a)")
130 int do1(int a) {
131 return a;
132 }
133 }
134
135 @Test
136 public void testMArgumentsDouble0() {
137 TestRootNode<MArgumentsDouble0> root = createRoot(MArgumentsDouble0Factory.getInstance());
138 Assert.assertEquals(42, executeWith(root, 42, 0));
139 }
140
141 @NodeChild("a")
142 abstract static class MArgumentsDouble0 extends ValueNode {
143
144 static boolean guard(int a1, Object a2) {
145 return a1 == 42 && a2.equals(new Integer(42));
146 }
147
148 @Specialization(guards = "guard(a,a)")
149 int do1(int a) {
150 return a;
151 }
152 }
153
154 @Test
155 public void testMArgumentsDouble1() {
156 TestRootNode<MArgumentsDouble1> root = createRoot(MArgumentsDouble1Factory.getInstance());
157 Assert.assertEquals(42, executeWith(root, 42, 41));
158 }
159
160 @NodeChildren({@NodeChild("a"), @NodeChild("b")})
161 abstract static class MArgumentsDouble1 extends ValueNode {
162
163 static boolean guard(int a1, double a2) {
164 return a1 == 42 && a2 == 41;
165 }
166
167 @Specialization(guards = "guard(a,b)")
168 int do1(int a, @SuppressWarnings("unused") double b) {
169 return a;
170 }
171 }
172
173 @Test
174 public void testMArgumentsDouble2() {
175 TestRootNode<MArgumentsDouble2> root = createRoot(MArgumentsDouble2Factory.getInstance());
176 Assert.assertEquals(42, executeWith(root, 42, 41.0));
177 }
178
179 @NodeChildren({@NodeChild("a"), @NodeChild("b")})
180 abstract static class MArgumentsDouble2 extends ValueNode {
181
182 static boolean guard(double a1, int a2) {
183 return a1 == 41 && a2 == 42;
184 }
185
186 @Specialization(guards = "guard(b,a)")
187 int do1(int a, @SuppressWarnings("unused") double b) {
188 return a;
189 }
190 }
191
192 @Test
193 public void testMArgumentsDouble3() {
194 TestRootNode<MArgumentsDouble3> root = createRoot(MArgumentsDouble3Factory.getInstance());
195 Assert.assertEquals(42, executeWith(root, 42, 41.0));
196 }
197
198 @NodeChildren({@NodeChild("a"), @NodeChild("b")})
199 abstract static class MArgumentsDouble3 extends ValueNode {
200
201 static boolean guard(Object a1, double a2) {
202 return new Double(41.0).equals(a1) && a2 == 41;
203 }
204
205 @Specialization(guards = "guard(b,b)")
206 int do1(int a, @SuppressWarnings("unused") double b) {
207 return a;
208 }
209 }
210
211 abstract static class MArgumentsError0 extends ValueNode {
212
213 static boolean guard() {
214 return true;
215 }
216
217 @ExpectError("Error parsing expression 'guard(': -- line 1 col 7: \")\" expected%")
218 @Specialization(guards = "guard(")
219 int do1() {
220 return 42;
221 }
222 }
223
224 abstract static class MArgumentsError1 extends ValueNode {
225
226 static boolean guard() {
227 return true;
228 }
229
230 @ExpectError("Error parsing expression 'guard)': -- line 1 col 6: EOF expected%")
231 @Specialization(guards = "guard)")
232 int do1() {
233 return 42;
234 }
235
236 }
237
238 abstract static class MArgumentsError2 extends ValueNode {
239
240 static boolean guard() {
241 return true;
242 }
243
244 @ExpectError("Error parsing expression 'guard(a)': a cannot be resolved.")
245 @Specialization(guards = "guard(a)")
246 int do1() {
247 return 42;
248 }
249 }
250
251 @NodeChild("b")
252 abstract static class MArgumentsError3 extends ValueNode {
253
254 static boolean guard() {
255 return true;
256 }
257
258 @ExpectError("Error parsing expression 'guard(a)': a cannot be resolved.")
259 @Specialization(guards = "guard(a)")
260 int do1(int b) {
261 return b;
262 }
263 }
264
265 }