2024-06-14 05:57:38 +00:00
|
|
|
// compile all test files using:
|
|
|
|
// ls Test/JavaSources/*.java | grep -v ".*Main.java" | xargs -I {} cabal run compiler {}
|
2024-06-14 06:11:58 +00:00
|
|
|
// compile (in project root) using:
|
2024-06-20 13:07:02 +00:00
|
|
|
// javac -g:none -sourcepath Test/JavaSources/ Test/JavaSources/Main.java
|
2024-06-14 05:57:38 +00:00
|
|
|
// 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;
|
2024-06-14 06:11:58 +00:00
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
assert malicious.cursedFormatting(i) == i;
|
|
|
|
}
|
2024-06-14 05:57:38 +00:00
|
|
|
}
|
|
|
|
}
|