2023-12-24 22:17:08 +00:00
|
|
|
import {run} from "../target/js/ludus.js"
|
|
|
|
import * as fs from "node:fs/promises"
|
|
|
|
import t from "tap"
|
|
|
|
|
|
|
|
const case_path = "./cases"
|
|
|
|
const files = await fs.readdir(case_path)
|
|
|
|
|
|
|
|
for (const file of files) {
|
2023-12-25 00:12:04 +00:00
|
|
|
const source = await fs.readFile(`${case_path}/${file}`, {encoding: "utf8"})
|
|
|
|
const first_line = source.split("\n")[0]
|
2023-12-24 22:17:08 +00:00
|
|
|
const expected = first_line.split("EXPECT")[1].trim()
|
2023-12-25 00:12:04 +00:00
|
|
|
if (expected === "PANIC") expect_panic(file, source)
|
|
|
|
else expect_result(file, source, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_panic(file, source) {
|
|
|
|
const result = run(source).errors[0]
|
|
|
|
t.test(`testing ${file}: EXPECT PANIC`, t => {
|
|
|
|
t.ok(result)
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_result(file, source, expected) {
|
|
|
|
const result = run(source).result
|
|
|
|
t.test(`testing ${file}: EXPECT ${expected}, GOT ${result}`, t => {
|
|
|
|
t.equal(expected, result)
|
|
|
|
t.end()
|
|
|
|
})
|
2023-12-24 22:17:08 +00:00
|
|
|
}
|