35 lines
1.5 KiB
Java
35 lines
1.5 KiB
Java
|
// compile (in project root) using:
|
||
|
// javac -g:none -sourcepath Test/JavaSources/ Test/JavaSources/Main.java
|
||
|
// compile all test files using:
|
||
|
// ls Test/JavaSources/*.java | grep -v ".*Main.java" | xargs -I {} cabal run compiler {}
|
||
|
// afterwards, run using
|
||
|
// java -ea -cp Test/JavaSources/ Main
|
||
|
|
||
|
public class Main {
|
||
|
public static void main(String[] args)
|
||
|
{
|
||
|
TestEmpty empty = new TestEmpty();
|
||
|
TestFields fields = new TestFields();
|
||
|
TestConstructor constructor = new TestConstructor(42);
|
||
|
TestMultipleClasses multipleClasses = new TestMultipleClasses();
|
||
|
TestRecursion recursion = new TestRecursion(10);
|
||
|
TestMalicious malicious = new TestMalicious();
|
||
|
|
||
|
// constructing a basic class works
|
||
|
assert empty != null;
|
||
|
// initializers (and default initializers to 0/null) work
|
||
|
assert fields.a == 0 && fields.b == 42;
|
||
|
// constructor parameters override initializers
|
||
|
assert constructor.a == 42;
|
||
|
// multiple classes within one file work. Referencing another classes fields/methods works.
|
||
|
assert multipleClasses.a.a == 42;
|
||
|
// self-referencing classes work.
|
||
|
assert recursion.child.child.child.child.child.value == 5;
|
||
|
// self-referencing methods work.
|
||
|
assert recursion.fibonacci(15) == 610;
|
||
|
// intentionally dodgy expressions work
|
||
|
assert malicious.assignNegativeIncrement(42) == -42;
|
||
|
assert malicious.tripleAddition(1, 2, 3) == 6;
|
||
|
}
|
||
|
}
|