From 8afa3b8461b86d8b4acf6a82d4daf6862756aa03 Mon Sep 17 00:00:00 2001 From: Bruder John Date: Wed, 3 Jul 2024 17:41:17 +0200 Subject: [PATCH] Added Own Tests --- src/test/java/semantic/BeginnToTAST.java | 45 +++++++++++++++++++ .../input/johnsTests/FieldTests.java | 5 +++ 2 files changed, 50 insertions(+) create mode 100644 src/test/java/semantic/BeginnToTAST.java create mode 100644 src/test/resources/input/johnsTests/FieldTests.java diff --git a/src/test/java/semantic/BeginnToTAST.java b/src/test/java/semantic/BeginnToTAST.java new file mode 100644 index 0000000..8b59666 --- /dev/null +++ b/src/test/java/semantic/BeginnToTAST.java @@ -0,0 +1,45 @@ +package semantic; + +import ast.ProgramNode; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTree; +import org.junit.jupiter.api.Test; +import parser.astBuilder.ASTBuilder; +import parser.generated.SimpleJavaLexer; +import parser.generated.SimpleJavaParser; + +import java.io.IOException; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BeginnToTAST { + + @Test + public void FieldTests() { + SemanticAnalyzer.clearAnalyzer(); + + CharStream codeCharStream = null; + try { + codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/johnsTests/FieldTests.java")); + } catch (IOException e) { + throw new RuntimeException(e); + } + SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream); + CommonTokenStream tokenStream = new CommonTokenStream(lexer); + + SimpleJavaParser parser = new SimpleJavaParser(tokenStream); + ParseTree parseTree = parser.program(); // parse the input + + /* ------------------------- AST builder -> AST ------------------------- */ + ASTBuilder astBuilder = new ASTBuilder(); + ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree); + + var result = SemanticAnalyzer.generateTast(abstractSyntaxTree); + + assertTrue(SemanticAnalyzer.errors.isEmpty()); + } + +} diff --git a/src/test/resources/input/johnsTests/FieldTests.java b/src/test/resources/input/johnsTests/FieldTests.java new file mode 100644 index 0000000..5a8eea4 --- /dev/null +++ b/src/test/resources/input/johnsTests/FieldTests.java @@ -0,0 +1,5 @@ +public class Test{ + + int a = 10; + +} \ No newline at end of file