ContextAnalysis: Make naught comparable to struct again.
This commit is contained in:
72
src/test/java/NaughtTest.java
Normal file
72
src/test/java/NaughtTest.java
Normal file
@@ -0,0 +1,72 @@
|
||||
import de.hsrm.compiler.Klang.ContextAnalysis;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class NaughtTest {
|
||||
@Test
|
||||
void shouldBeComparableToStruct() {
|
||||
ParseTree tree = Helper.prepareParser("""
|
||||
struct bar { a: int; }
|
||||
|
||||
function foo(): int {
|
||||
let a: bar = create bar(1);
|
||||
if (a == naught) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
foo();
|
||||
""");
|
||||
var ctxAnal = new ContextAnalysis(
|
||||
Helper.getFuncs(tree),
|
||||
Helper.getStructs(tree),
|
||||
Helper.getEnums(tree)
|
||||
);
|
||||
|
||||
assertDoesNotThrow(() -> ctxAnal.visit(tree));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeAssignableToStruct() {
|
||||
ParseTree tree = Helper.prepareParser("""
|
||||
struct bar { a: int; }
|
||||
|
||||
function foo(): int {
|
||||
let a: bar = naught;
|
||||
return 1;
|
||||
}
|
||||
|
||||
foo();
|
||||
""");
|
||||
var ctxAnal = new ContextAnalysis(
|
||||
Helper.getFuncs(tree),
|
||||
Helper.getStructs(tree),
|
||||
Helper.getEnums(tree)
|
||||
);
|
||||
|
||||
assertDoesNotThrow(() -> ctxAnal.visit(tree));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeReturnable() {
|
||||
ParseTree tree = Helper.prepareParser("""
|
||||
struct bar { a: int; }
|
||||
|
||||
function foo(): bar {
|
||||
return naught;
|
||||
}
|
||||
|
||||
foo();
|
||||
""");
|
||||
var ctxAnal = new ContextAnalysis(
|
||||
Helper.getFuncs(tree),
|
||||
Helper.getStructs(tree),
|
||||
Helper.getEnums(tree)
|
||||
);
|
||||
|
||||
assertDoesNotThrow(() -> ctxAnal.visit(tree));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user