new tests
This commit is contained in:
8
.idea/modules/CompilerProjekt.test.iml
generated
Normal file
8
.idea/modules/CompilerProjekt.test.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
</module>
|
@ -16,6 +16,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class LexerGrammarParserTest {
|
||||
|
||||
@ -49,9 +50,26 @@ class LexerGrammarParserTest {
|
||||
"Expr.stups",
|
||||
"GeneralWhile.stups",
|
||||
"GeneralIfElse.stups"})
|
||||
void testVariousPrograms(String prog) {
|
||||
void testCorrectPrograms(String prog) {
|
||||
final Lexer lex = getLexer(prog);
|
||||
|
||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"FailingSemicolon.stups",
|
||||
"FailingMissingBrace.stups",
|
||||
"FailingMissingBrace2.stups",
|
||||
"FailingMissingMain.stups",
|
||||
"FailingMissingMain2.stups",
|
||||
"FailingEmptyParExpr.stups",
|
||||
"FailingEmptyParExpr2.stups",
|
||||
"FailingWrongStatement.stups",
|
||||
"FailingWrongStatement2.stups",
|
||||
"FailingWrongStatement3.stups"})
|
||||
void testIncorrectPrograms(String prog) {
|
||||
final Lexer lex = getLexer(prog);
|
||||
|
||||
assertThatThrownBy(() -> parser.parse(lex.getAllTokens(), lex.getVocabulary())).isInstanceOf(ParseException.class);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,10 @@ class TypeCheckerTest {
|
||||
"boolean b = 1 >;",
|
||||
"boolean b = >= 1;",
|
||||
"boolean b = 1 ==;",
|
||||
"boolean b = 1 !=;"})
|
||||
"boolean b = 1 !=;",
|
||||
"boolean b = !;",
|
||||
"boolean b = <;",
|
||||
"boolean b = true !false;"})
|
||||
void testBinaryOperatorIncorrect(String expr) {
|
||||
assertThatThrownBy(() -> TypeChecker.validate(this.getTree(expr))).isInstanceOfAny(OperatorUsageException.class,
|
||||
ParseException.class);
|
||||
|
@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
public static void main(String[] args) {
|
||||
if () {
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
class MyClass {
|
||||
public static void main(String[] args) {
|
||||
i = 1 * ();
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
class MyClass {
|
@ -0,0 +1 @@
|
||||
class MyClass }
|
@ -0,0 +1,3 @@
|
||||
class MyClass {
|
||||
int x = 5;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
class MyClass {
|
||||
public static void mainmain(String[] args) {
|
||||
int i = 1;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
;
|
@ -0,0 +1,5 @@
|
||||
class MyClass {
|
||||
public static void main(String[] args) {
|
||||
int x;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
class MyClass {
|
||||
public static void main(String[] args) {
|
||||
5;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
class MyClass {
|
||||
public static void main(String[] args) {
|
||||
int x = 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user