更新:添加doString方法及对应的单元测试

This commit is contained in:
2026-04-05 08:19:20 +08:00
parent 14526b8dc2
commit 8f1d409cf5
10 changed files with 337 additions and 146 deletions

View File

@ -1,4 +1,4 @@
package luarunner
package luaRunner
import std.unittest.* // cjlint-ignore G.PKG.01
import std.fs.* // cjlint-ignore G.PKG.01
@ -254,7 +254,58 @@ func testRedirectIoRead(): Unit {
}
// ====================
// 6. 错误码与回调
// 6. doString 测试
// ====================
@Test
func testDoStringSimple(): Unit {
let runner = LuaRunner()
let res = runner.doString("return 1 + 1")
@Expect(res, "2")
}
@Test
func testDoStringWithGlobal(): Unit {
let runner = LuaRunner()
let res = runner.doString("g = 42; return g")
@Expect(res, "42")
}
@Test
func testDoStringNoReturn(): Unit {
let runner = LuaRunner()
try {
runner.doString("x = 10")
fail("Should throw bad ret error")
} catch (e: LuaError) {
@Expect(e.code, 5011)
}
}
@Test
func testDoStringSyntaxError(): Unit {
let runner = LuaRunner()
try {
runner.doString("if true then")
fail("Should throw syntax error")
} catch (e: LuaError) {
@Expect(e.code, 5020)
}
}
@Test
func testDoStringNilReturn(): Unit {
let runner = LuaRunner()
try {
runner.doString("return nil")
fail("Should throw bad ret error")
} catch (e: LuaError) {
@Expect(e.code, 5011)
}
}
// ====================
// 7. 错误码与回调
// ====================
@Test