Files
plainleaf/client/space_lua/lua.test.ts
T
Matouš Jan FialkaandGitHub 80f31da16b Fix arithmetic coercion - refactored and enhanced (#1576)
The Lua 5.4 compatible `tonumber` implementation completely reworked

- custom char-by-char parser (no regexes)
- proper Lua space handling
- support for heximal integers and floats
- support for scientific float notation
- extended tests
- updated website docs

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2025-10-01 11:30:58 +02:00

72 lines
2.0 KiB
TypeScript

import { parse } from "./parse.ts";
import { luaBuildStandardEnv } from "./stdlib.ts";
import { LuaEnv, LuaRuntimeError, LuaStackFrame } from "./runtime.ts";
import { evalStatement } from "./eval.ts";
import { assert } from "@std/assert/assert";
import { fileURLToPath } from "node:url";
Deno.test("[Lua] Core language", async () => {
await runLuaTest("./language_core_test.lua");
});
Deno.test("[Lua] Table tests", async () => {
await runLuaTest("./stdlib/table_test.lua");
});
Deno.test("[Lua] String to number tests", async () => {
await runLuaTest("./tonumber_test.lua");
});
Deno.test("[Lua] String tests", async () => {
await runLuaTest("./stdlib/string_test.lua");
// await runLuaTest("./stdlib/string_test2.lua");
});
Deno.test("[Lua] Space Lua tests", async () => {
await runLuaTest("./stdlib/space_lua_test.lua");
});
Deno.test("[Lua] OS tests", async () => {
await runLuaTest("./stdlib/os_test.lua");
});
Deno.test("[Lua] Math tests", async () => {
await runLuaTest("./stdlib/math_test.lua");
});
Deno.test("[Lua] JS tests", async () => {
await runLuaTest("./stdlib/js_test.lua");
});
Deno.test("[Lua] Global functions tests", async () => {
await runLuaTest("./stdlib/global_test.lua");
});
Deno.test("[Lua] Encoding functions tests", async () => {
await runLuaTest("./stdlib/encoding_test.lua");
});
Deno.test("[Lua] Lume functions tests", async () => {
await runLuaTest("./lume_test.lua");
});
async function runLuaTest(luaPath: string) {
const luaFile = await Deno.readTextFile(
fileURLToPath(new URL(luaPath, import.meta.url)),
);
const chunk = parse(luaFile, {});
const env = new LuaEnv(luaBuildStandardEnv());
const sf = LuaStackFrame.createWithGlobalEnv(env, chunk.ctx);
try {
await evalStatement(chunk, env, sf);
} catch (e: any) {
if (e instanceof LuaRuntimeError) {
console.error(`Error evaluating script:`, e.toPrettyString(luaFile));
} else {
console.error(`Error evaluating script:`, e);
}
assert(false);
}
}