Skip to content

Commit

Permalink
Add type assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdok committed Apr 20, 2019
1 parent c21d046 commit 58259b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/_support/Assertions/TypeAssertion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local assert = require('luassert.assert')
local say = require("say")

local function type_of(state, arguments)
if #arguments ~= 2 then
return negative
end

local expectedType = arguments[1]
local actualType = type(arguments[2])

return expectedType == actualType
end

say:set("assertion.type_of.positive", "Expected type of %s. Actual: %s")
say:set("assertion.type_of.negative", "Unexpected type of %s. Actual: %s")
assert:register("assertion", "type_of", type_of, "assertion.type_of.positive", "assertion.type_of.negative")

23 changes: 23 additions & 0 deletions tests/_support/Assertions/TypeAssertion_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe("TypeAssertion", function()

it("should check if a variable is of type function", function()
callback = function()
end

assert.type_of('function', callback)

assert.is_not_type_of('function', 1)
end)

it("should check if a variable is of type string", function()
assert.type_of('string', 'Value')

assert.is_not_type_of('string', 1)
end)

it("should check if a variable is of type table", function()
assert.type_of('table', {})

assert.is_not_type_of('table', 1)
end)
end)
1 change: 1 addition & 0 deletions tests/bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local manifestPath = 'AddonName.txt'

require "TimeAssertion"
require "ChatAssertion"
require "TypeAssertion"

local esouiLoader = require 'EsoLuaLoader'
esouiLoader:initializeGlobals()
Expand Down

0 comments on commit 58259b3

Please sign in to comment.