use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.
the class NodeUtilTest method testForEachChild.
@Test
public void testForEachChild() {
TestRootNode root = new TestRootNode();
TestForEachNode testForEachNode = new TestForEachNode(1);
root.child0 = testForEachNode;
TestNode testNode1 = new TestNode();
testForEachNode.firstChild = testNode1;
TestNode testNode2 = new TestNode();
testForEachNode.children[0] = testNode2;
TestNode testNode3 = new TestNode();
testForEachNode.lastChild = testNode3;
root.adoptChildren();
int[] count = new int[1];
NodeUtil.forEachChild(root, new NodeVisitor() {
public boolean visit(Node node) {
Assert.assertSame(testForEachNode, node);
count[0]++;
return true;
}
});
Assert.assertEquals(1, count[0]);
count[0] = 0;
NodeUtil.forEachChild(testForEachNode, new NodeVisitor() {
public boolean visit(Node node) {
((VisitableNode) node).visited++;
count[0]++;
return true;
}
});
Assert.assertEquals(3, count[0]);
Assert.assertEquals(1, testNode1.visited);
Assert.assertEquals(1, testNode2.visited);
Assert.assertEquals(1, testNode3.visited);
}
Aggregations