Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java @ 11544:e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 16:11:15 +0200 |
parents | 80de3bbfa8b9 |
children | 5d1308c78ddc |
comparison
equal
deleted
inserted
replaced
11543:90c45cbbf9de | 11544:e5b5a5cb0ac7 |
---|---|
35 import com.oracle.truffle.api.nodes.*; | 35 import com.oracle.truffle.api.nodes.*; |
36 import com.oracle.truffle.api.nodes.NodeInfo.Kind; | 36 import com.oracle.truffle.api.nodes.NodeInfo.Kind; |
37 | 37 |
38 public class PolymorphicTest { | 38 public class PolymorphicTest { |
39 | 39 |
40 private static void assertParent(Node expectedParent, Node child) { | |
41 Node parent = child.getParent(); | |
42 while (parent != null && parent != expectedParent) { | |
43 parent = parent.getParent(); | |
44 } | |
45 | |
46 if (parent != expectedParent) { | |
47 assertEquals(expectedParent, parent); | |
48 } | |
49 } | |
50 | |
40 @Test | 51 @Test |
41 public void testJustSpecialize() { | 52 public void testJustSpecialize() { |
42 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 53 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
43 assertEquals("(int,int)", executeWith(node, 42, 42)); | 54 assertEquals("(int,int)", executeWith(node, 42, 42)); |
44 assertEquals("(boolean,boolean)", executeWith(node, false, false)); | 55 assertEquals("(boolean,boolean)", executeWith(node, false, false)); |
45 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 56 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
46 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 57 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
47 assertEquals(Kind.SPECIALIZED, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 58 assertEquals(Kind.SPECIALIZED, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
48 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 59 assertParent(node.getNode(), node.getNode().getLeft()); |
49 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 60 assertParent(node.getNode(), node.getNode().getRight()); |
50 } | 61 } |
51 | 62 |
52 @Test | 63 @Test |
53 public void testPolymorphic2() { | 64 public void testPolymorphic2() { |
54 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 65 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
55 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 66 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
56 assertEquals("(int,int)", executeWith(node, 42, 42)); | 67 assertEquals("(int,int)", executeWith(node, 42, 42)); |
57 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 68 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
58 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 69 assertParent(node.getNode(), node.getNode().getLeft()); |
59 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 70 assertParent(node.getNode(), node.getNode().getRight()); |
60 } | 71 } |
61 | 72 |
62 @Test | 73 @Test |
63 public void testPolymorphic3() { | 74 public void testPolymorphic3() { |
64 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 75 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
65 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 76 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
66 assertEquals("(boolean,boolean)", executeWith(node, true, false)); | 77 assertEquals("(boolean,boolean)", executeWith(node, true, false)); |
67 assertEquals("(int,int)", executeWith(node, 42, 42)); | 78 assertEquals("(int,int)", executeWith(node, 42, 42)); |
68 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 79 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
69 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 80 assertParent(node.getNode(), node.getNode().getLeft()); |
70 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 81 assertParent(node.getNode(), node.getNode().getRight()); |
71 } | 82 } |
72 | 83 |
73 @Test | 84 @Test |
74 public void testGenericLimitReached() { | 85 public void testGenericLimitReached() { |
75 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 86 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
76 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 87 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
77 assertEquals("(int,boolean)", executeWith(node, 42, false)); | 88 assertEquals("(int,boolean)", executeWith(node, 42, false)); |
78 assertEquals("(boolean,boolean)", executeWith(node, true, false)); | 89 assertEquals("(boolean,boolean)", executeWith(node, true, false)); |
79 assertEquals("(int,int)", executeWith(node, 42, 42)); | 90 assertEquals("(int,int)", executeWith(node, 42, 42)); |
80 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 91 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
81 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 92 assertParent(node.getNode(), node.getNode().getLeft()); |
82 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 93 assertParent(node.getNode(), node.getNode().getRight()); |
83 } | 94 } |
84 | 95 |
85 @Test | 96 @Test |
86 public void testGenericInitial() { | 97 public void testGenericInitial() { |
87 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 98 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
88 assertEquals("(generic,generic)", executeWith(node, "", "")); | 99 assertEquals("(generic,generic)", executeWith(node, "1", "1")); |
89 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 100 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
90 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 101 assertParent(node.getNode(), node.getNode().getLeft()); |
91 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 102 assertParent(node.getNode(), node.getNode().getRight()); |
92 } | 103 } |
93 | 104 |
94 @Test | 105 @Test |
95 public void testGenericPolymorphic1() { | 106 public void testGenericPolymorphic1() { |
96 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); | 107 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
97 assertEquals("(boolean,int)", executeWith(node, false, 42)); | 108 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
98 assertEquals("(boolean,boolean)", executeWith(node, false, false)); | 109 assertEquals("(boolean,boolean)", executeWith(node, false, false)); |
99 assertEquals("(generic,generic)", executeWith(node, "", "")); | 110 assertEquals("(generic,generic)", executeWith(node, "", "")); |
100 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); | 111 assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
101 /* Assertions for bug GRAAL-425 */ | 112 /* Assertions for bug GRAAL-425 */ |
102 assertEquals(node.getNode(), node.getNode().getLeft().getParent()); | 113 assertParent(node.getNode(), node.getNode().getLeft()); |
103 assertEquals(node.getNode(), node.getNode().getRight().getParent()); | 114 assertParent(node.getNode(), node.getNode().getRight()); |
104 } | 115 } |
105 | 116 |
106 @SuppressWarnings("unused") | 117 @SuppressWarnings("unused") |
107 @PolymorphicLimit(3) | 118 @PolymorphicLimit(3) |
108 abstract static class Node1 extends BinaryNode { | 119 abstract static class Node1 extends BinaryNode { |