Add tests for worldedit.lua/luatransform

This commit is contained in:
sfan5 2024-04-20 20:23:49 +02:00
parent 883caff58d
commit 372847e774
2 changed files with 38 additions and 1 deletions

@ -51,7 +51,7 @@ function worldedit.luatransform(pos1, pos2, code)
while pos.z <= pos2.z do while pos.z <= pos2.z do
local good, err = pcall(func, pos) local good, err = pcall(func, pos)
if not good then -- Runtime error if not good then -- Runtime error
return err return tostring(err)
end end
pos.z = pos.z + 1 pos.z = pos.z + 1
end end

@ -542,6 +542,43 @@ do
end end
end end
register_test("Code")
register_test("worldedit.lua", function()
-- syntax error
local err, ret = worldedit.lua("?")
assert(ret == nil)
assert(err:find("unexpected symbol"))
-- runtime error
local err, ret = worldedit.lua("error(1234)")
assert(ret == nil)
assert(err:find("1234"))
-- normal operation
local err, ret = worldedit.lua("return name..tostring(player == nil)..tostring(pos == nil)", "nobody")
assert(err == nil)
assert(ret == "\"nobodytruetrue\"")
end)
register_test("worldedit.luatransform", function()
local pos1, pos2 = area.get(2)
-- syntax error
local err = worldedit.luatransform(pos1, pos2, "?")
assert(err:find("unexpected symbol"))
-- runtime error
local err = worldedit.luatransform(pos1, pos2, "error(2345)")
assert(err:find("2345"))
-- normal operation
local err = worldedit.luatransform(pos1, pos2,
"minetest.swap_node(pos, {name=" .. ("%q"):format(testnode1) .. "})")
assert(err == nil)
check.filled(pos1, pos1, testnode1)
end)
--------------------- ---------------------
-- Main function -- Main function
--------------------- ---------------------