【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-ASTUtilTest.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// $Id: ASTUtilTest.java 7461 2005-07-12 20:49:35Z oneovthafew $
package org.hibernate.test.ast;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.hibernate.hql.ast.util.ASTUtil;
import antlr.ASTFactory;
import antlr.collections.AST;
/**
* Unit test for ASTUtil.
*/
public class ASTUtilTest extends TestCase {
private ASTFactory factory;
/**
* Standard JUnit test case constructor.
*
* @param name The name of the test case.
*/
public ASTUtilTest(String name) {
super( name );
}
protected void setUp() throws Exception {
super.setUp();
factory = new ASTFactory();
}
public void testCreate() throws Exception {
AST n = ASTUtil.create( factory, 1, "one");
assertNull( n.getFirstChild() );
assertEquals("one",n.getText());
assertEquals(1,n.getType());
}
/**
* Test adding a tree of children.
*/
public void testCreateTree() throws Exception {
AST[] tree = new AST[4];
AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent");
AST parent = tree[1] = ASTUtil.create(factory,2,"parent");
AST child = tree[2] = ASTUtil.create(factory,3,"child");
AST baby = tree[3] = ASTUtil.create(factory,4,"baby");
AST t = ASTUtil.createTree( factory, tree);
assertSame(t,grandparent);
assertSame(parent,t.getFirstChild());
assertSame(child,t.getFirstChild().getFirstChild());
assertSame(baby,t.getFirstChild().getFirstChild().getFirstChild());
}
public void testFindPreviousSibling() throws Exception {
AST child1 = ASTUtil.create(factory,2, "child1");
AST child2 = ASTUtil.create(factory,3, "child2");
AST n = factory.make( new AST[] {
ASTUtil.create(factory, 1, "parent"),
child1,
child2,
});
assertSame(child1,ASTUtil.findPreviousSibling( n,child2));
Exception e = null;
try {
ASTUtil.findPreviousSibling(child1,null);
}
catch (Exception x) {
e = x;
}
assertNotNull(e);
}
public static Test suite() {
return new TestSuite( ASTUtilTest.class );
}
}
上一篇:
ASTUtil.java
下一篇:
【3月31日-4月1日】“2018中国人保购车节暨第九届郑州国际汽车博览会”即将上线,现在抢票还送“钱”!