2024-10-04 23:15:50 +08:00
|
|
|
import { parse } from "$common/space_lua/parse.ts";
|
|
|
|
import { luaBuildStandardEnv } from "$common/space_lua/stdlib.ts";
|
2024-10-26 22:02:37 +08:00
|
|
|
import { LuaEnv, LuaStackFrame } from "$common/space_lua/runtime.ts";
|
2024-10-04 23:15:50 +08:00
|
|
|
import { evalStatement } from "$common/space_lua/eval.ts";
|
|
|
|
import { assert } from "@std/assert/assert";
|
|
|
|
Deno.test("Lua language tests", async () => {
|
2024-10-11 21:34:27 +08:00
|
|
|
// Read the Lua file
|
|
|
|
const luaFile = await Deno.readTextFile(
|
|
|
|
new URL("./language_test.lua", import.meta.url).pathname,
|
|
|
|
);
|
|
|
|
const chunk = parse(luaFile, {});
|
|
|
|
const env = new LuaEnv(luaBuildStandardEnv());
|
2024-10-20 21:06:23 +08:00
|
|
|
const sf = new LuaStackFrame(new LuaEnv(), chunk.ctx);
|
2024-10-04 23:15:50 +08:00
|
|
|
|
2024-10-11 21:34:27 +08:00
|
|
|
try {
|
2024-10-20 21:06:23 +08:00
|
|
|
await evalStatement(chunk, env, sf);
|
2024-10-11 21:34:27 +08:00
|
|
|
} catch (e: any) {
|
2024-10-26 22:02:37 +08:00
|
|
|
console.error(`Error evaluating script:`, e.toPrettyString(luaFile));
|
2024-10-11 21:34:27 +08:00
|
|
|
assert(false);
|
|
|
|
}
|
2024-10-04 23:15:50 +08:00
|
|
|
});
|