mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-27 11:10:39 +01:00
Add tests for worldedit.lua/luatransform
This commit is contained in:
parent
883caff58d
commit
372847e774
@ -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
|
||||||
---------------------
|
---------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user