added scanner parser test for ClassCanBeBytecoded

This commit is contained in:
JonathanFleischmann 2024-07-03 17:16:13 +02:00
parent 93279743f2
commit 43a05c761a
2 changed files with 114 additions and 19 deletions

View File

@ -0,0 +1,90 @@
package MoreTestResources.AST;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class AbstractSyntax_ClassCanBeBytecoded {
public static Program get() {
List<Declaration> declarations = List.of(
new Declaration(
"c",
Type.REFERENCE("ClassCanBeBytecoded")
),
new Declaration(
"x",
Type.INT
)
);
List<Method> methods = getMethods();
List<Constructor> constructors = getConstructors();
return new Program(
List.of(
new Class(
"ClassCanBeBytecoded",
null,
declarations,
methods,
constructors
)
)
);
}
private static List<Constructor> getConstructors() {
return List.of(getConstructor1());
}
private static Constructor getConstructor1() {
List<Parameter> parameters = List.of();
List<Statement> statementList = List.of();
Block block = new Block(
statementList
);
return new Constructor(
"ClassCanBeBytecoded",
parameters,
block
);
}
private static List<Method> getMethods() {
return List.of(getMethod1());
}
private static Method getMethod1() {
List<Parameter> parameters = List.of(
new Parameter(
"var1",
Type.INT
)
);
List<Statement> statementList = List.of(
new Print(
new FieldVarAccess(
false,
null,
"var1"
)
),
new Return(
new FieldVarAccess(
false,
null,
"var1"
)
)
);
Block block = new Block(
statementList
);
return new Method(
Type.INT,
"test",
parameters,
block
);
}
}

View File

@ -179,15 +179,9 @@ class ScannerParserTests {
// -> Corresponding Test files in src/test/testFiles/MoreTestFiles // -> Corresponding Test files in src/test/testFiles/MoreTestFiles
@Test @Test
void testPublicClass() { void testClassCanBeBytecoded() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/PublicClass.java")); Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassCanBeBytecoded.java"));
assertEquals(AbstractSyntax_PublicClass.get(), resultAst); assertEquals(AbstractSyntax_ClassCanBeBytecoded.get(), resultAst);
}
@Test
void testClassWithField() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithField.java"));
assertEquals(AbstractSyntax_ClassWithField.get(), resultAst);
} }
@Test @Test
@ -197,9 +191,9 @@ class ScannerParserTests {
} }
@Test @Test
void testClassWithMethod() { void testClassWithConstructorAndMethodCall() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithMethod.java")); Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithConstructorAndMethodCall.java"));
assertEquals(AbstractSyntax_ClassWithMethod.get(), resultAst); assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
} }
@Test @Test
@ -214,22 +208,33 @@ class ScannerParserTests {
assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst); assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst);
} }
@Test
void testClassWithField() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithField.java"));
assertEquals(AbstractSyntax_ClassWithField.get(), resultAst);
}
@Test
void testClassWithMethod() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithMethod.java"));
assertEquals(AbstractSyntax_ClassWithMethod.get(), resultAst);
}
@Test @Test
void testClassWithMethodAndField() { void testClassWithMethodAndField() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithMethodAndField.java")); Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithMethodAndField.java"));
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst); assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
} }
@Test
void testClassWithConstructorAndMethodCall() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ClassWithConstructorAndMethodCall.java"));
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
}
@Test @Test
void testComplexClass() { void testComplexClass() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ComplexClass.java")); Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/ComplexClass.java"));
assertEquals(AbstractSyntax_ComplexClass.get(), resultAst); assertEquals(AbstractSyntax_ComplexClass.get(), resultAst);
} }
@Test
void testPublicClass() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/MoreTestFiles/PublicClass.java"));
assertEquals(AbstractSyntax_PublicClass.get(), resultAst);
}
} }