mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-20 17:08:12 +00:00
更新:添加doString方法及对应的单元测试
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user