-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters