forked from JavaTX/JavaCompilerCore
Added test case for instanceof in syntaxtreegenerator
This commit is contained in:
parent
2368a087c0
commit
24900b8fcc
16
resources/syntaxtreegenerator/Instanceof.ast
Normal file
16
resources/syntaxtreegenerator/Instanceof.ast
Normal file
@ -0,0 +1,16 @@
|
||||
class Instanceof {
|
||||
|
||||
Instanceof(){
|
||||
super(());
|
||||
}
|
||||
void checkInstanceof(){
|
||||
TPH a;
|
||||
a = 4;
|
||||
return a instanceof java.lang.Integer;
|
||||
}
|
||||
|
||||
Instanceof(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}
|
8
resources/syntaxtreegenerator/javFiles/Instanceof.jav
Normal file
8
resources/syntaxtreegenerator/javFiles/Instanceof.jav
Normal file
@ -0,0 +1,8 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Instanceof{
|
||||
void checkInstanceof() {
|
||||
var a = 4;
|
||||
return (a instanceof java.lang.Integer);
|
||||
}
|
||||
}
|
@ -1,5 +1,61 @@
|
||||
package syntaxtreegenerator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
|
||||
public class TestNewFeatures {
|
||||
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
final String testFileDirectory = "resources/syntaxtreegenerator/javFiles/";
|
||||
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
||||
File dir = new File(testFileDirectory);
|
||||
for (File f : dir.listFiles(new JavFilter())) {
|
||||
String basefilename = f.getName().replace(".jav", "");
|
||||
// javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
|
||||
javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instanceOfTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Instanceof")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Instanceof")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for applyLambda.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for applyLambda.jav");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JavFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.getName().contains(".jav"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user