diff --git a/tests/blueprint/unit.spec.lua b/tests/blueprint/unit.spec.lua index 1b613d67a8..ab70ecd87e 100644 --- a/tests/blueprint/unit.spec.lua +++ b/tests/blueprint/unit.spec.lua @@ -20,6 +20,8 @@ --** SOFTWARE. --****************************************************************************************************** +require "./tests/packages/fafMockLibrary.lua" + ---@type Luft local luft = require "./tests/packages/luft" diff --git a/tests/packages/fafMockLibrary.lua b/tests/packages/fafMockLibrary.lua new file mode 100644 index 0000000000..930604c6a4 --- /dev/null +++ b/tests/packages/fafMockLibrary.lua @@ -0,0 +1,46 @@ +import = function(file) + return require('.' .. file) +end + +-- Vector2 is needed in utils but not provided outside the game, so it has to be created here +local Vector2Meta = { + __index = function(t, k) + if k == 'x' then + return t[1] + elseif k == 'y' then + return t[2] + elseif k == 'z' then + return t[3] + else + error("bad argument #2 to `?' ('x', 'y', or 'z' expected)", 1) + end + end, + + __newindex = function(t, k, v) + if k == 'x' then + t[1] = v + elseif k == 'y' then + t[2] = v + elseif k == 'z' then + t[3] = v + else + error("bad argument #2 to `?' ('x', 'y', or 'z' expected)", 1) + end + end, +} + +Vector2 = function(...) + if arg.n ~= 2 then + error("expected 2 args, but got " .. arg.n) + end + if not type(arg[1]) == "number" then + error("number expected but got " .. type(arg[1])) + end + if not type(arg[2]) == "number" then + error("number expected but got " .. type(arg[2])) + end + + local newVector2 = {arg[1], arg[2]} + setmetatable(newVector2, Vector2Meta) + return newVector2 +end diff --git a/tests/utility/color.spec.lua b/tests/utility/color.spec.lua index d95093533e..9b51087a85 100644 --- a/tests/utility/color.spec.lua +++ b/tests/utility/color.spec.lua @@ -2,6 +2,8 @@ --** Shared under the MIT license --************************************************************************************************** +require "./tests/packages/fafMockLibrary.lua" + local luft = require "./tests/packages/luft" -- color library diff --git a/tests/utility/string.spec.lua b/tests/utility/string.spec.lua index 07c361d047..3cbb9c23b7 100644 --- a/tests/utility/string.spec.lua +++ b/tests/utility/string.spec.lua @@ -1,48 +1,8 @@ +require "./tests/packages/fafMockLibrary.lua" + -- Test framework local luft = require "./tests/packages/luft" --- Vector2 is needed in utils but not provided outside the game, so it has to be created here -local Vector2Meta = { - __index = function(t, k) - if k == 'x' then - return t[1] - elseif k == 'y' then - return t[2] - elseif k == 'z' then - return t[3] - else - error("bad argument #2 to `?' ('x', 'y', or 'z' expected)", 1) - end - end, - - __newindex = function(t, k, v) - if k == 'x' then - t[1] = v - elseif k == 'y' then - t[2] = v - elseif k == 'z' then - t[3] = v - else - error("bad argument #2 to `?' ('x', 'y', or 'z' expected)", 1) - end - end, -} -Vector2 = function(...) - if arg.n ~= 2 then - error("expected 2 args, but got " .. arg.n) - end - if not type(arg[1]) == "number" then - error("number expected but got " .. type(arg[1])) - end - if not type(arg[2]) == "number" then - error("number expected but got " .. type(arg[2])) - end - - local newVector2 = {arg[1], arg[2]} - setmetatable(newVector2, Vector2Meta) - return newVector2 -end - -- These functions are imported to the global scope in globalInit and RuleInit require "./lua/system/utils.lua"