72 lines
2.1 KiB
Java
72 lines
2.1 KiB
Java
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));
|
|
}
|
|
} |