Skip to content

Commit

Permalink
added is/isNot truthy and falsy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocipa committed Oct 9, 2022
1 parent beaea50 commit 3de8a38
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/is.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ end



checks.truthy = function(v1, _)
if not v1 then
return string.format("expected %s to be truthy, but it is falsy", tostring(v1))
end

return true
end





checks.falsy = function(v1, _)
if v1 then
return string.format("expected %s to be falsy, but it is truthy", tostring(v1))
end

return true
end





checks.nan = function(v1, _)
local isNumber = checks.number(v1)
if isNumber ~= true then return isNumber end
Expand Down
24 changes: 24 additions & 0 deletions src/isNot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ end



checks.truthy = function(v1, _)
if v1 then
return string.format("expected %s to not be truthy, but it is truthy", tostring(v1))
end

return true
end





checks.falsy = function(v1, _)
if not v1 then
return string.format("expected %s to not be falsy, but it is falsy", tostring(v1))
end

return true
end





checks.nan = function(v1, _)
local isNumber = is.number(v1)

Expand Down
5 changes: 5 additions & 0 deletions src/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type is = {
server: () -> boolean,
client: () -> boolean,

type: (type: string) -> boolean,

none: () -> boolean,
string: () -> boolean,
number: () -> boolean,
Expand All @@ -27,6 +29,9 @@ export type is = {

equal: (value: any) -> boolean,

truthy: () -> boolean,
falsy: () -> boolean,

nan: () -> boolean,
inf: () -> boolean,

Expand Down
2 changes: 1 addition & 1 deletion wally.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ registry = "test"

[[package]]
name = "ocipa/expect"
version = "0.1.5"
version = "0.2.0"
dependencies = []
4 changes: 3 additions & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "ocipa/expect"
version = "0.1.5"
version = "0.2.0"
authors = ["Ocipa <[email protected]>"]
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"

exclude = ["*.spec.lua", "README.md", "test*", "modules", "assets", "*.rbxl*"]

[dev-dependencies]

0 comments on commit 3de8a38

Please sign in to comment.