Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negated equality assertions #42

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Added

- Added negated equality assertions for comparative and length. (#40)

## Changed


Expand Down
2 changes: 1 addition & 1 deletion src/assertions.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "./assertions/length.typ" as length
#import "./assertions/comparative.typ": min, max, eq
#import "./assertions/comparative.typ": min, max, eq, neq
#import "./assertions/string.typ": *

/// Asserts that the given value is contained within the provided list. Useful for complicated enumeration types.
Expand Down
18 changes: 14 additions & 4 deletions src/assertions/comparative.typ
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@
}

/// Asserts that tested value is exactly equal to argument
#let eq(rhs) = {
assert-positive-type(rhs, types: (int,), name: "Equality")
#let eq(arg) = {
assert-positive-type(arg, types: (int,), name: "Equality")

return (
condition: (self, it) => it == rhs,
message: (self, it) => "Must be exactly " + str(rhs),
condition: (self, it) => it == arg,
message: (self, it) => "Must be exactly " + str(arg),
)
}

/// Asserts that tested value is not exactly equal to argument
#let neq(arg) = {
assert-positive-type(arg, types: (int,), name: "Equality")

return (
condition: (self, it) => it != arg,
message: (self, it) => "Must not equal " + str(arg),
)
}
18 changes: 14 additions & 4 deletions src/assertions/length.typ
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@
}

/// Asserts that tested value's length is exactly equal to argument
#let equals(rhs) = {
assert-positive-type(rhs, types: (int,), name: "Exact length")
#let equals(arg) = {
assert-positive-type(arg, types: (int,), name: "Exact length")

return (
condition: (self, it) => it.len() == rhs,
message: (self, it) => "Length must equal " + str(rhs),
condition: (self, it) => it.len() == arg,
message: (self, it) => "Length must equal " + str(arg),
)
}

/// Asserts that tested value's length is not equal to argument
#let neq(arg) = {
assert-positive-type(arg, types: (int,), name: "Exact length")

return (
condition: (self, it) => it.len() != rhs,
message: (self, it) => "Length must not equal " + str(rhs),
)
}