JavaCompilerCore/test/syntaxTree/NodeEqualTest.java

60 lines
1.8 KiB
Java
Raw Normal View History

2014-03-14 15:34:25 +00:00
package syntaxTree;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.junit.Test;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
2014-09-04 14:35:44 +00:00
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
2014-03-14 15:34:25 +00:00
import junit.framework.TestCase;
public class NodeEqualTest extends TestCase{
2014-03-17 16:55:55 +00:00
private static final String rootDirectory = System.getProperty("user.dir")+"/test/syntaxTree/";
private static final String testFile = "NodeEqualTest.jav";
2014-03-14 15:34:25 +00:00
@Test
public void test(){
LoggerConfiguration logConfig = new LoggerConfiguration();
logConfig.setOutput(Section.TYPEINFERENCE, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
MyCompilerAPI compiler2 = MyCompiler.getAPI(logConfig);
2014-03-14 15:34:25 +00:00
SourceFile tree = null;
2014-03-17 16:55:55 +00:00
SourceFile tree2 = null;
2014-03-14 15:34:25 +00:00
try {
tree = compiler.parse(new File(rootDirectory + testFile));
2014-03-17 16:55:55 +00:00
tree2 = compiler2.parse(new File(rootDirectory + testFile));
2014-03-14 15:34:25 +00:00
} catch (IOException | yyException e) {
e.printStackTrace();
fail();
}
2014-03-17 16:55:55 +00:00
recursivlyCheckEqual(tree, tree2);
2014-03-14 15:34:25 +00:00
}
private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){
for(SyntaxTreeNode n1 : node1.getChildren()){
int matches = 0;
for(SyntaxTreeNode n2 : node2.getChildren()){
if(n2.equals(n1)){
2014-03-17 16:55:55 +00:00
System.out.println(n2 + " == "+n1);
2014-03-14 15:34:25 +00:00
matches++;
this.recursivlyCheckEqual(n1, n2);
2014-03-17 16:55:55 +00:00
}else{
System.out.println(n2 + " != "+ n1);
2014-03-14 15:34:25 +00:00
}
}
2014-03-17 16:55:55 +00:00
System.out.println("");
assertTrue("Nur eines der Children darf gleich sein, nicht "+matches, matches == 1 && node2.getChildren().size()>0);
2014-03-14 15:34:25 +00:00
}
}
}