Skip to content

Commit 1b0e7f9

Browse files
authored
Merge pull request #36 from source-academy/compiler
Change representation of class file to match JVM
2 parents 425581b + 2e31f31 commit 1b0e7f9

17 files changed

+1178
-39
lines changed

src/compiler/__tests__/test-utils.ts renamed to src/compiler/__tests__/__utils__/test-utils.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { inspect } from "util";
2-
import { Compiler } from "../compiler";
3-
import { BinaryWriter } from "../binary-writer";
4-
import { AST } from "../../ast/types/packages-and-modules";
2+
import { Compiler } from "../../compiler";
3+
import { BinaryWriter } from "../../binary-writer";
4+
import { AST } from "../../../ast/types/packages-and-modules";
5+
import { javaPegGrammar } from "../../grammar"
56
import { execSync } from "child_process";
67

78
import * as peggy from "peggy";
@@ -15,7 +16,6 @@ export type testCase = {
1516

1617
const debug = false;
1718
const pathToTestDir = "./src/compiler/__tests__/";
18-
const javaPegGrammar = fs.readFileSync('./src/compiler/main.pegjs', 'utf-8');
1919
const parser = peggy.generate(javaPegGrammar, {
2020
allowedStartRules: ["CompilationUnit"],
2121
});
@@ -43,7 +43,3 @@ export function runTest(program: string, expectedLines: string[]) {
4343

4444
expect(actualLines).toStrictEqual(expectedLines);
4545
}
46-
47-
describe("compiler's test utils", () => {
48-
it("Prevent jest from complaining", () => { });
49-
});

src/compiler/__tests__/tests/arithmeticExpression.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -85,4 +85,4 @@ export const arithmeticExpressionTest = () => describe("arithmetic expression",
8585
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
8686
it(comment, () => runTest(program, expectedLines));
8787
}
88-
});
88+
});

src/compiler/__tests__/tests/array.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -207,4 +207,4 @@ export const arrayTest = () => describe("arrays", () => {
207207
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
208208
it(comment, () => runTest(program, expectedLines));
209209
}
210-
});
210+
});

src/compiler/__tests__/tests/class.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -151,4 +151,4 @@ export const classTest = () => describe("fields and methods of class", () => {
151151
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
152152
it(comment, () => runTest(program, expectedLines));
153153
}
154-
});
154+
});

src/compiler/__tests__/tests/for.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -165,4 +165,4 @@ export const forTest = () => describe("for statements", () => {
165165
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
166166
it(comment, () => runTest(program, expectedLines));
167167
}
168-
});
168+
});

src/compiler/__tests__/tests/ifElse.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -321,4 +321,4 @@ export const ifElseTest = () => describe("if else statements", () => {
321321
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
322322
it(comment, () => runTest(program, expectedLines));
323323
}
324-
});
324+
});

src/compiler/__tests__/tests/import.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -50,4 +50,4 @@ export const importTest = () => describe("imports", () => {
5050
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
5151
it(comment, () => runTest(program, expectedLines));
5252
}
53-
});
53+
});

src/compiler/__tests__/tests/methodInvocation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -159,4 +159,4 @@ export const methodInvocationTest = () => describe("method invocations", () => {
159159
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
160160
it(comment, () => runTest(program, expectedLines));
161161
}
162-
});
162+
});

src/compiler/__tests__/tests/println.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{
@@ -119,4 +119,4 @@ export const printlnTest = () => describe("println", () => {
119119
const { comment: comment, program: program, expectedLines: expectedLines } = testCase;
120120
it(comment, () => runTest(program, expectedLines));
121121
}
122-
});
122+
});

src/compiler/__tests__/tests/unaryExpression.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
runTest,
33
testCase,
4-
} from "../test-utils";
4+
} from "../__utils__/test-utils";
55

66
const testCases: testCase[] = [
77
{

0 commit comments

Comments
 (0)