Changed Some Tests

This commit is contained in:
Bruder John 2024-07-03 20:36:57 +02:00
parent 1bcf396f95
commit d4be77ceb2
5 changed files with 53 additions and 22 deletions

View File

@ -26,10 +26,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
import semantic.exceptions.AlreadyDeclaredException;
import semantic.exceptions.MultipleReturnTypes;
import semantic.exceptions.NotDeclaredException;
import semantic.exceptions.TypeMismatchException;
import semantic.exceptions.*;
import semantic.exceptions.NotDeclaredException;
import static org.junit.jupiter.api.Assertions.*;
@ -282,6 +279,45 @@ public class EndToTypedAstTest {
}
@Test
public void BothTypesMustBeSameGreaterSmallerEqual(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/BothTypesMustBeSame.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertEquals(3, SemanticAnalyzer.errors.size());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
}
@Test
public void NoSuchType(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/ClassNotDeclared.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertEquals(1, SemanticAnalyzer.errors.size());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
}
@Test
public void FieldIsNotVisible(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/FieldIsNotVisible.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertEquals(1, SemanticAnalyzer.errors.size());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotVisibleException));
}
// ------------------ Helpers ------------------
/**

View File

@ -5,5 +5,18 @@ public class AllFeaturesClassExample {
while (a > bool) {
a--;
}
if (a == bool) {
} else {
}
if (a < bool) {
} else {
}
}
}

View File

@ -4,9 +4,4 @@ public class Test {
public House1 h;
}
public class House {
}

View File

@ -1,13 +0,0 @@
// @expected: TypeMismatchException
public class Test{
public void test(boolean b){
if(b == 2){
} else {
}
}
}