Closed
Description
Description
Try to generate tests for the following class, set timeout at least to 60s.
import org.antlr.runtime.tree.TreeVisitor;
import org.antlr.runtime.tree.TreeVisitorAction;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.tool.ast.GrammarAST;
public class Grammarin {
public void setGrammarPtr(final org.antlr.v4.tool.Grammar g, GrammarAST tree) {
if (tree != null) {
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
v.visit(tree, new TreeVisitorAction() {
public Object pre(Object t) {
((GrammarAST) t).g = g;
return t;
}
public Object post(Object t) {
return t;
}
});
}
}
}
The following code i generated:
@Test
@DisplayName("setGrammarPtr: -> tree != null : True")
public void testSetGrammarPtr_TreeNotEqualsNull_2() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
Grammarin grammarin = new Grammarin();
GrammarRootAST tree = new GrammarRootAST(null);
tree.token = null;
Class baseTreeClazz = Class.forName("org.antlr.runtime.tree.BaseTree");
Field childrenField = baseTreeClazz.getDeclaredField("children");
childrenField.setAccessible(true);
childrenField.get(tree) = new ArrayList();
grammarin.setGrammarPtr(null, tree);
}
Line with getter leads to the compilation error
childrenField.get(tree) = new ArrayList(); - variable expected
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done