comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SourceSectionTest.java @ 16967:c5db657d93c1

Truffle-DSL: added test for source sections in @CreateCast methods.
author Christian Humer <christian.humer@gmail.com>
date Wed, 27 Aug 2014 11:35:59 +0200
parents f5541b01f374
children a665483c3881
comparison
equal deleted inserted replaced
16966:e92bc7d8e2dd 16967:c5db657d93c1
24 24
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; 25 import static com.oracle.truffle.api.dsl.test.TestHelper.*;
26 import static org.hamcrest.CoreMatchers.*; 26 import static org.hamcrest.CoreMatchers.*;
27 import static org.junit.Assert.*; 27 import static org.junit.Assert.*;
28 28
29 import org.junit.*;
29 import org.junit.experimental.theories.*; 30 import org.junit.experimental.theories.*;
30 import org.junit.runner.*; 31 import org.junit.runner.*;
31 32
32 import com.oracle.truffle.api.dsl.*; 33 import com.oracle.truffle.api.dsl.*;
33 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection0Factory; 34 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection0Factory;
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.*; 35 import com.oracle.truffle.api.dsl.test.SourceSectionTestFactory.SourceSection1Factory;
36 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode;
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
35 import com.oracle.truffle.api.nodes.*; 39 import com.oracle.truffle.api.nodes.*;
36 import com.oracle.truffle.api.source.*; 40 import com.oracle.truffle.api.source.*;
37 41
38 @RunWith(Theories.class) 42 @RunWith(Theories.class)
39 public class SourceSectionTest { 43 public class SourceSectionTest {
52 expectSourceSection(root.getNode(), section); 56 expectSourceSection(root.getNode(), section);
53 assertThat((int) executeWith(root, value2), is(value2)); 57 assertThat((int) executeWith(root, value2), is(value2));
54 expectSourceSection(root.getNode(), section); 58 expectSourceSection(root.getNode(), section);
55 } 59 }
56 60
57 private void expectSourceSection(Node root, SourceSection section) { 61 private static void expectSourceSection(Node root, SourceSection section) {
58 assertThat(root.getSourceSection(), is(sameInstance(section))); 62 assertThat(root.getSourceSection(), is(sameInstance(section)));
59 for (Node child : root.getChildren()) { 63 for (Node child : root.getChildren()) {
60 if (child instanceof ArgumentNode) { 64 if (child instanceof ArgumentNode) {
61 continue; 65 continue;
62 } 66 }
99 @Fallback 103 @Fallback
100 Object do4(Object a) { 104 Object do4(Object a) {
101 return a; // the generic answer to all questions 105 return a; // the generic answer to all questions
102 } 106 }
103 } 107 }
108
109 @Test
110 public void testCreateCast() {
111 SourceSection section = new NullSourceSection("a", "b");
112 TestRootNode<SourceSection1> root = createRootPrefix(SourceSection1Factory.getInstance(), true, section);
113 expectSourceSection(root.getNode(), section);
114 assertThat((int) executeWith(root, 1), is(1));
115 expectSourceSection(root.getNode(), section);
116 }
117
118 @NodeChild("a")
119 static class SourceSection1 extends ValueNode {
120
121 public SourceSection1(SourceSection section) {
122 super(section);
123 }
124
125 @CreateCast("a")
126 public ValueNode cast(ValueNode node) {
127 assert getSourceSection() != null;
128 return node;
129 }
130
131 @Specialization
132 int do0(int a) {
133 return a;
134 }
135
136 }
104 } 137 }