Files
plainleaf/client/space_lua/lua.test.ts
T
Matouš Jan FialkaandGitHub e0182b3bb4 [Space Lua] Implement native Lua pattern matching engine (#1838)
* Add Lua *pattern matching engine* (`pattern.ts`) that directly ports
  `lstrlib.c` semantics.

* Integrate the new engine into the `string` API for `find`, `match`,
  `gmatch`, and `gsub` functions.

* Add a pattern test suite (`pattern_test.lua`) covering character
  classes, repetition quantifiers, edge cases as well as error
  conditions.

* Refactor `string_test.lua` to remove duplicated pattern tests that
  are now covered by the pattern test suite.

* Fix `string.rep` separator support.

* Fix `string.sub` index handling.

* Remove the obsolete `string_test2.lua` file.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-02-13 14:18:55 +01:00

107 lines
2.8 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] Core language (labels and goto)", async () => {
await runLuaTest("./goto_test.lua");
});
Deno.test("[Lua] Core language (length)", async () => {
await runLuaTest("./len_test.lua");
});
Deno.test("[Lua] Core language (truthiness)", async () => {
await runLuaTest("./truthiness_test.lua");
});
Deno.test("[Lua] Core language (arithmetic)", async () => {
await runLuaTest("./arithmetic_test.lua");
});
Deno.test("[Lua] Core language (metamethods)", async () => {
await runLuaTest("./metamethods_test.lua");
});
Deno.test("[Lua] Load tests", async () => {
await runLuaTest("./stdlib/load_test.lua");
});
Deno.test("[Lua] Core language (length)", async () => {
await runLuaTest("./len_test.lua");
});
Deno.test("[Lua] Format tests", async () => {
await runLuaTest("./stdlib/format_test.lua");
});
Deno.test("[Lua] String to number tests", async () => {
await runLuaTest("./tonumber_test.lua");
});
Deno.test("[Lua] Pattern tests", async () => {
await runLuaTest("./stdlib/pattern_test.lua");
});
Deno.test("[Lua] String tests", async () => {
await runLuaTest("./stdlib/string_test.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] Crypto functions tests", async () => {
await runLuaTest("./stdlib/crypto_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);
}
}