Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 committed Dec 22, 2024
1 parent 205a6d0 commit 72c4aed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 42 deletions.
2 changes: 2 additions & 0 deletions tests/blueprint/unit.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
--** SOFTWARE.
--******************************************************************************************************

require "./tests/packages/fafMockLibrary.lua"

---@type Luft
local luft = require "./tests/packages/luft"

Expand Down
46 changes: 46 additions & 0 deletions tests/packages/fafMockLibrary.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/utility/color.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
--** Shared under the MIT license
--**************************************************************************************************

require "./tests/packages/fafMockLibrary.lua"

local luft = require "./tests/packages/luft"

-- color library
Expand Down
44 changes: 2 additions & 42 deletions tests/utility/string.spec.lua
Original file line number Diff line number Diff line change
@@ -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"

Expand Down

0 comments on commit 72c4aed

Please sign in to comment.