diff --git a/resources/syntaxtreegenerator/Instanceof.ast b/resources/syntaxtreegenerator/Instanceof.ast new file mode 100644 index 00000000..993d7740 --- /dev/null +++ b/resources/syntaxtreegenerator/Instanceof.ast @@ -0,0 +1,16 @@ +class Instanceof { + +Instanceof(){ + super(()); + } + void checkInstanceof(){ + TPH a; + a = 4; + return a instanceof java.lang.Integer; + } + + Instanceof(){ + super(()); + } + +} \ No newline at end of file diff --git a/resources/syntaxtreegenerator/javFiles/Instanceof.jav b/resources/syntaxtreegenerator/javFiles/Instanceof.jav new file mode 100644 index 00000000..5b383437 --- /dev/null +++ b/resources/syntaxtreegenerator/javFiles/Instanceof.jav @@ -0,0 +1,8 @@ +import java.lang.Integer; + +public class Instanceof{ + void checkInstanceof() { + var a = 4; + return (a instanceof java.lang.Integer); + } +} \ No newline at end of file diff --git a/src/test/java/syntaxtreegenerator/TestNewFeatures.java b/src/test/java/syntaxtreegenerator/TestNewFeatures.java index f35b0f11..5008c55d 100644 --- a/src/test/java/syntaxtreegenerator/TestNewFeatures.java +++ b/src/test/java/syntaxtreegenerator/TestNewFeatures.java @@ -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 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; + } } \ No newline at end of file