Skip to content

Commit

Permalink
testing code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
XeroOl committed Dec 31, 2024
1 parent 1fafd9f commit b276957
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 57 deletions.
68 changes: 34 additions & 34 deletions spec/acc_spec.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("acc", function()
before_each(function()
helper.reset()
helper.init()
end)

after_each(function()
xero = nil
end)

it("sets values at the right time", function()
xero.acc {1, 100, "bumpy"}
update(0.5)
assert.equal(nil, helper.get_mod("bumpy"))
update(1)
assert.equal("100", helper.get_mod("bumpy"))
end)

it("adds when called multiple times", function()
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
update(0.5)
assert.equal(nil, helper.get_mod("bumpy"))
update(1)
assert.equal("500", helper.get_mod("bumpy"))
end)
end)
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("acc", function()
before_each(function()
helper.reset()
helper.init()
end)

after_each(function()
xero = nil
end)

it("sets values at the right time", function()
xero.acc {1, 100, "bumpy"}
update(0.5)
assert.equal(nil, helper.get_mod("bumpy"))
update(1)
assert.equal("100", helper.get_mod("bumpy"))
end)

it("adds when called multiple times", function()
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
xero.acc {1, 100, "bumpy"}
update(0.5)
assert.equal(nil, helper.get_mod("bumpy"))
update(1)
assert.equal("500", helper.get_mod("bumpy"))
end)
end)
1 change: 0 additions & 1 deletion spec/definemod_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ describe("definemod", function()
update(2)
end)

-- TODO
end)
1 change: 0 additions & 1 deletion spec/eases_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

local function check_doesnt_crash(fn)
for i = 0, 1, 0.2 do
Expand Down
30 changes: 14 additions & 16 deletions spec/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,31 @@ local initcommand = "return " .. body:match('"%%(.-)"')
initcommand = assert(loadstring(initcommand, "template/main.xml"))()

function helper.init()
local h = helper

h.foreground = mock.newactorframe()
helper.foreground = mock.newactorframe()
loadfile = cachedloadfile
initcommand(h.foreground)
initcommand(helper.foreground)
xero.loadfile = dummyloadfile
xero.package.preload.mods = function() end

h.template = mock.newactor()
mock.add_child(h.foreground, h.template)
h.template:addcommand("Init", xero.init_command)
h.template:playcommand("Init")
helper.template = mock.newactor()
mock.add_child(helper.foreground, helper.template)
helper.template:addcommand("Init", xero.init_command)
helper.template:playcommand("Init")

h.layout = mock.newactorframe()
mock.add_child(h.foreground, h.layout)
helper.layout = mock.newactorframe()
mock.add_child(helper.foreground, helper.layout)
local pp1 = mock.newactor("PP[1]")
local pp2 = mock.newactor("PP[2]")
local pc1 = mock.newactor("PC[1]")
local pc2 = mock.newactor("PC[2]")
local pj1 = mock.newactor("PJ[1]")
local pj2 = mock.newactor("PJ[2]")
mock.add_child(h.layout, pp1)
mock.add_child(h.layout, pp2)
mock.add_child(h.layout, pc1)
mock.add_child(h.layout, pc2)
mock.add_child(h.layout, pj1)
mock.add_child(h.layout, pj2)
mock.add_child(helper.layout, pp1)
mock.add_child(helper.layout, pp2)
mock.add_child(helper.layout, pc1)
mock.add_child(helper.layout, pc2)
mock.add_child(helper.layout, pj1)
mock.add_child(helper.layout, pj2)
end

function helper.on()
Expand Down
1 change: 0 additions & 1 deletion spec/node_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("node", function()
before_each(function()
Expand Down
1 change: 0 additions & 1 deletion spec/setdefault_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("setdefault", function()
before_each(function()
Expand Down
3 changes: 1 addition & 2 deletions spec/sort_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("sort", function()
setup(function()
Expand All @@ -24,4 +23,4 @@ describe("sort", function()
xero.stableSort(testtable,function(a, b) return a < b end)
assert.is.same(testtable, {1,1,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,45,45,57,57,69,69,79,79,1000,1000})
end)
end)
end)
4 changes: 3 additions & 1 deletion spec/spellcard_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local helper = require("spec.helper")
local update = helper.update

describe("spellcard plugin", function()
before_each(function()
Expand All @@ -15,6 +14,9 @@ describe("spellcard plugin", function()
it("doesn't crash", function()
local spellcards = xero.require('spellcards')
spellcards.insert {0, 10, "my cool card of spelling", 1000, "#fcf"}
spellcards.insert {20, 30, "my cool card of spelling", 999, {1,0.75, 1}}
helper.update(0)
end)

-- any more testing is really testing our mock more than the functionality
end)

0 comments on commit b276957

Please sign in to comment.