comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CreateCastTest.java @ 13531:1f870eaf1e96

Truffle-DSL: Added test for @CreateCast.
author Christian Humer <christian.humer@gmail.com>
date Tue, 07 Jan 2014 20:05:55 +0100
parents
children b466199f19e1
comparison
equal deleted inserted replaced
13530:0576e9a0358e 13531:1f870eaf1e96
1 /*
2 * Copyright (c) 2012, 2012, 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 org.junit.*;
26
27 import com.oracle.truffle.api.dsl.*;
28 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode1Factory;
29 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode2Factory;
30 import com.oracle.truffle.api.dsl.test.CreateCastTestFactory.CreateCastNode3Factory;
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
33 import com.oracle.truffle.api.nodes.*;
34
35 @SuppressWarnings("unused")
36 public class CreateCastTest {
37
38 @Test
39 public void testCastNode1() {
40 TestRootNode<CreateCastNode1> root = TestHelper.createRoot(CreateCastNode1Factory.getInstance());
41 Assert.assertEquals(1, root.getNode().invocations);
42 }
43
44 @Test
45 public void testCastNode2() {
46 TestRootNode<CreateCastNode2> root = TestHelper.createRoot(CreateCastNode2Factory.getInstance());
47 Assert.assertEquals(2, root.getNode().invocations);
48 }
49
50 @Test
51 public void testCastNode3() {
52 TestRootNode<CreateCastNode3> root = TestHelper.createRoot(CreateCastNode3Factory.getInstance());
53 Assert.assertEquals(1, root.getNode().invocations);
54 }
55
56 @NodeChild("a")
57 abstract static class CreateCastNode1 extends ValueNode {
58
59 int invocations = 0;
60
61 @CreateCast({"a"})
62 public ValueNode createCast(ValueNode node) {
63 invocations++;
64 return node;
65 }
66
67 @Specialization
68 public int doInteger(int a) {
69 throw new AssertionError();
70 }
71 }
72
73 @NodeChildren({@NodeChild("a"), @NodeChild("b")})
74 abstract static class CreateCastNode2 extends ValueNode {
75
76 int invocations = 0;
77
78 @CreateCast({"a", "b"})
79 public ValueNode createCast(ValueNode node) {
80 invocations++;
81 return node;
82 }
83
84 @Specialization
85 public int doInteger(int a, int b) {
86 throw new AssertionError();
87 }
88 }
89
90 @NodeChild(value = "a", type = ValueNode[].class)
91 abstract static class CreateCastNode3 extends ValueNode {
92
93 int invocations = 0;
94
95 @CreateCast("a")
96 public ValueNode[] createCast(ValueNode[] node) {
97 invocations++;
98 return node;
99 }
100
101 @Specialization
102 public int doInteger(int a) {
103 throw new AssertionError();
104 }
105 }
106
107 @NodeChild("a")
108 abstract static class CreateCastFailNode1 extends ValueNode {
109
110 @ExpectError({"Specified child '' not found."})
111 @CreateCast({""})
112 public ValueNode createCast(Node child) {
113 throw new AssertionError();
114 }
115
116 @Specialization
117 public int doInteger(int a) {
118 throw new AssertionError();
119 }
120 }
121
122 }