|
1 | | -import { describe, it } from "node:test"; |
2 | | -import assert from "node:assert/strict"; |
3 | | -describe("The project setup", () => { |
4 | | - it("can at least run tests", () => { |
5 | | - assert.deepEqual(1, 1); |
6 | | - }); |
7 | | -}); |
| 1 | +import { describe, it } from "node:test" |
| 2 | +import assert from "node:assert/strict" |
| 3 | +import compile from "../src/compiler.js" |
| 4 | + |
| 5 | +const sampleProgram = "print(0)" |
| 6 | + |
| 7 | +describe("The compiler", () => { |
| 8 | + it("throws when the output type is missing", () => { |
| 9 | + assert.throws(() => compile(sampleProgram), /Unknown output type/) |
| 10 | + }) |
| 11 | + it("throws when the output type is unknown", () => { |
| 12 | + assert.throws(() => compile(sampleProgram, "no such type"), /Unknown output type/) |
| 13 | + }) |
| 14 | + it("accepts the parsed option", () => { |
| 15 | + const compiled = compile(sampleProgram, "parsed") |
| 16 | + assert(compiled.startsWith("Syntax is ok")) |
| 17 | + }) |
| 18 | + it("accepts the analyzed option", () => { |
| 19 | + const compiled = compile(sampleProgram, "analyzed") |
| 20 | + assert(compiled.kind === "Program") |
| 21 | + }) |
| 22 | + it("accepts the optimized option", () => { |
| 23 | + const compiled = compile(sampleProgram, "optimized") |
| 24 | + assert(compiled.kind === "Program") |
| 25 | + }) |
| 26 | + it("generates js code when given the js option", () => { |
| 27 | + const compiled = compile(sampleProgram, "js") |
| 28 | + assert(compiled.startsWith("console.log(0)")) |
| 29 | + }) |
| 30 | +}) |
0 commit comments