Skip to content

Commit

Permalink
fix: closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenstein64 committed Feb 13, 2024
1 parent f788b00 commit 1f66de8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/bustez/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ local function is_type(state, arguments, level)
return arguments.n > 1 and type(arguments[1]) == arguments[2]
end

local function is_ok(state, arguments, level)
set_failure_message(state, arguments[2])
return arguments[1] ~= nil
end

return function()
local is = namespaces.modifier.is.callback
local is_not = namespaces.modifier.no.callback
Expand All @@ -26,19 +31,18 @@ return function()
luassert:register("modifier", "at", is)
luassert:register("modifier", "never", is_not)

say:set("assertion.ok.positive", "expected to be truthy, but value was:\n%s")
say:set("assertion.ok.negative", "Expected to not be truthy, but value was:\n%s")
say:set("assertion.ok.positive", "Expected to be non-nil, but value was:\n%s")
say:set("assertion.ok.negative", "Expected to be nil, but value was:\n%s")
say:set("assertion.a.positive", "Expected values to be the same.\nPassed in: %s\nExpected:\ntype %s")
say:set("assertion.a.negative", "Expected values to not be the same.\nPassed in: %s\nExpected:\ntype %s")
say:set("assertion.like.positive", "Expected objects to be the same.\nPassed in:\n%s\nExpected:\n%s")
say:set("assertion.like.negative", "Expected objects to not be the same.\nPassed in:\n%s\nDid not expect:\n%s")
say:set("assertion.throw.positive", "Expected a different error.\nCaught:\n%s\nExpected:\n%s")
say:set("assertion.throw.negative", "Expected no error, but caught:\n%s")

local truthy = namespaces.assertion.truthy.callback
local same = namespaces.assertion.same.callback
local has_error = namespaces.assertion.error.callback
luassert:register("assertion", "ok", truthy, "assertion.ok.positive", "assertion.ok.negative")
luassert:register("assertion", "ok", is_ok, "assertion.ok.positive", "assertion.ok.negative")
luassert:register("assertion", "like", same, "assertion.like.positive", "assertion.like.negative")
luassert:register("assertion", "look_like", same, "assertion.like.positive", "assertion.like.negative")
luassert:register("assertion", "throw", has_error, "assertion.throw.positive", "assertion.throw.negative")
Expand Down
4 changes: 2 additions & 2 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local assert = require("luassert")
local say = require("say")
local expect = require("bustez")()

expect(false).to.never.be.ok()
expect(nil).to.never.be.ok()
expect(false).to.be.ok()
expect(true).to.be.ok()
expect(true).to.be.have.been.was.at.is.are.has.does.ok()
expect(true).to.never.never.be.ok()
Expand Down Expand Up @@ -70,7 +70,7 @@ expect(fail).to.never.throw("o")
expect(fail).to.never.throw("Oh no!")

expect(function()
expect(false).to.be.ok("totally not okay!")
expect(nil).to.be.ok("totally not okay!")
end).to.match.error("totally not okay!")

local function assertFalse()
Expand Down

0 comments on commit 1f66de8

Please sign in to comment.