Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Jun 22, 2024
1 parent b06e44b commit 0992924
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"describe",
"before",
"after",
"it"
"it",
"pprint"
]
}
1 change: 1 addition & 0 deletions test/test.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local deftest = require("deftest.deftest")

function init(self)
deftest.add(require("test.test_event"))
deftest.add(require("test.test_event_logger"))
deftest.add(require("test.test_events"))

local is_report = sys.get_config("test.report") == "1"
Expand Down
19 changes: 18 additions & 1 deletion test/test_event.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
return function()
local event = require("event.event")
local event = {} --[[@as event]]

describe("Defold Event", function()
before(function()
event = require("event.event")
end)

it("Instantiate Event", function()
local test_event = event.create()
assert(test_event)
end)

it("Instantiate Event with callback", function()
local ctx = "some context"
local f = function(self, arg)
assert(self == "some context")
assert(arg == "arg")
end

local test_event = event.create(f, ctx)
assert(#test_event.callbacks == 1)

test_event:trigger("arg")
end)

it("Subscribe and Unsubscribe", function()
local test_event = event.create()
local f = function() end
Expand Down
33 changes: 33 additions & 0 deletions test/test_event_logger.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
return function()
local event = {} --[[@as event]]

describe("Defold Event", function()
before(function()
event = require("event.event")
end)

it("Event Set logger", function()
local EMPTY_FUNCTION = function(_, message, context) end
local logger = {
trace = EMPTY_FUNCTION,
debug = EMPTY_FUNCTION,
info = EMPTY_FUNCTION,
warn = EMPTY_FUNCTION,
error = EMPTY_FUNCTION,
}
event.set_logger(logger)
assert(event.logger == logger)
end)

it("Subscribe and Unsubscribe", function()
local test_event = event.create()
local f = function() end

test_event:subscribe(f)
assert(#test_event.callbacks == 1)

test_event:unsubscribe(f)
assert(#test_event.callbacks == 0)
end)
end)
end
3 changes: 2 additions & 1 deletion test/test_events.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
return function()
local events = require("event.events")
local events = {}

describe("Defold Events", function()
before(function()
events = require("event.events") --[[@as events]]
events.clear_all()
end)

Expand Down

0 comments on commit 0992924

Please sign in to comment.