mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
added test handler
This commit is contained in:
parent
5e54d112ce
commit
f15d2e31f7
2 changed files with 54 additions and 0 deletions
|
@ -72,6 +72,8 @@ dofile(wea.modpath.."/lib/wireframe/corner_set.lua")
|
||||||
dofile(wea.modpath.."/lib/wireframe/make_compass.lua")
|
dofile(wea.modpath.."/lib/wireframe/make_compass.lua")
|
||||||
dofile(wea.modpath.."/lib/wireframe/wire_box.lua")
|
dofile(wea.modpath.."/lib/wireframe/wire_box.lua")
|
||||||
|
|
||||||
|
wea.normalize_test = dofile(wea.modpath.."/lib/normalize_test.lua") -- For Test command
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
52
worldeditadditions/lib/normalize_test.lua
Normal file
52
worldeditadditions/lib/normalize_test.lua
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
-- ████████ ███████ ███████ ████████
|
||||||
|
-- ██ ██ ██ ██
|
||||||
|
-- ██ █████ ███████ ██
|
||||||
|
-- ██ ██ ██ ██
|
||||||
|
-- ██ ███████ ███████ ██
|
||||||
|
|
||||||
|
-- ██ ██ █████ ███ ██ ██████ ██ ███████ ██████
|
||||||
|
-- ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ███████ ███████ ██ ██ ██ ██ ██ ██ █████ ██████
|
||||||
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
-- ██ ██ ██ ██ ██ ████ ██████ ███████ ███████ ██ ██
|
||||||
|
|
||||||
|
-- Metatable for tests
|
||||||
|
local metatable = {
|
||||||
|
__call = function(self,name, ...)
|
||||||
|
return pcall(self.func, name, ...)
|
||||||
|
end,
|
||||||
|
help = function(self)
|
||||||
|
return "Params: " .. self.params .. "\n" .. self.description
|
||||||
|
end
|
||||||
|
}
|
||||||
|
metatable.__index = metatable
|
||||||
|
|
||||||
|
local normalize_test = function(test_name, def)
|
||||||
|
---
|
||||||
|
-- 1: Validation
|
||||||
|
---
|
||||||
|
if type(test_name) ~= "string" then
|
||||||
|
error("The test name is not a string.")
|
||||||
|
end
|
||||||
|
if type(def) ~= "table" then
|
||||||
|
error("The test definition is not a table.")
|
||||||
|
end
|
||||||
|
if type(def.description) ~= "string" then
|
||||||
|
error("The test description is not a string.")
|
||||||
|
end
|
||||||
|
if type(def.params) ~= "string" or #def.params == 0 then
|
||||||
|
error("The test params param is not valid.")
|
||||||
|
end
|
||||||
|
if type(def.func) ~= "function" then
|
||||||
|
error("The test function is not a function.")
|
||||||
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- 2: Normalisation
|
||||||
|
---
|
||||||
|
setmetatable(def, metatable)
|
||||||
|
|
||||||
|
return test_name, def
|
||||||
|
end
|
||||||
|
|
||||||
|
return normalize_test
|
Loading…
Reference in a new issue