Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/UnsupportedSpecializationTest.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/UnsupportedSpecializationTest.java@28479abd1a69 |
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 java.util.*; | |
26 | |
27 import org.junit.*; | |
28 | |
29 import com.oracle.truffle.api.dsl.*; | |
30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | |
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
32 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported1Factory; | |
33 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported2Factory; | |
34 import com.oracle.truffle.api.nodes.*; | |
35 | |
36 public class UnsupportedSpecializationTest { | |
37 | |
38 @Test | |
39 public void testUnsupported1() { | |
40 TestRootNode<Unsupported1> root = TestHelper.createRoot(Unsupported1Factory.getInstance()); | |
41 try { | |
42 TestHelper.executeWith(root, ""); | |
43 Assert.fail(); | |
44 } catch (UnsupportedSpecializationException e) { | |
45 Assert.assertNotNull(e.getSuppliedValues()); | |
46 Assert.assertEquals(1, e.getSuppliedValues().length); | |
47 Assert.assertEquals("", e.getSuppliedValues()[0]); | |
48 Assert.assertSame(root.getNode().getChildren().iterator().next(), e.getSuppliedNodes()[0]); | |
49 Assert.assertEquals(root.getNode(), e.getNode()); | |
50 } | |
51 } | |
52 | |
53 @NodeChild("a") | |
54 abstract static class Unsupported1 extends ValueNode { | |
55 | |
56 @Specialization | |
57 public int doInteger(@SuppressWarnings("unused") int a) { | |
58 throw new AssertionError(); | |
59 } | |
60 } | |
61 | |
62 @Test | |
63 public void testUnsupported2() { | |
64 TestRootNode<Unsupported2> root = TestHelper.createRoot(Unsupported2Factory.getInstance()); | |
65 try { | |
66 TestHelper.executeWith(root, "", 1); | |
67 Assert.fail(); | |
68 } catch (UnsupportedSpecializationException e) { | |
69 Assert.assertNotNull(e.getSuppliedValues()); | |
70 Assert.assertNotNull(e.getSuppliedNodes()); | |
71 Assert.assertEquals(3, e.getSuppliedValues().length); | |
72 Assert.assertEquals(3, e.getSuppliedNodes().length); | |
73 Assert.assertEquals("", e.getSuppliedValues()[0]); | |
74 Assert.assertEquals(false, e.getSuppliedValues()[1]); | |
75 Assert.assertEquals(null, e.getSuppliedValues()[2]); | |
76 List<Node> children = NodeUtil.findNodeChildren(root.getNode()); | |
77 Assert.assertSame(children.get(0), e.getSuppliedNodes()[0]); | |
78 Assert.assertNull(e.getSuppliedNodes()[1]); | |
79 Assert.assertSame(children.get(1), e.getSuppliedNodes()[2]); | |
80 Assert.assertEquals(root.getNode(), e.getNode()); | |
81 } | |
82 } | |
83 | |
84 @SuppressWarnings("unused") | |
85 @NodeChildren({@NodeChild("a"), @NodeChild("b")}) | |
86 abstract static class Unsupported2 extends ValueNode { | |
87 | |
88 @ShortCircuit("b") | |
89 public boolean needsB(Object a) { | |
90 return false; | |
91 } | |
92 | |
93 @Specialization | |
94 public int doInteger(int a, boolean hasB, int b) { | |
95 throw new AssertionError(); | |
96 } | |
97 } | |
98 | |
99 } |