diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d08f3d..f855479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Added +- Added negated equality assertions for comparative and length. (#40) + ## Changed diff --git a/src/assertions.typ b/src/assertions.typ index 13ee520..2138ad5 100644 --- a/src/assertions.typ +++ b/src/assertions.typ @@ -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. diff --git a/src/assertions/comparative.typ b/src/assertions/comparative.typ index 5ecb8bd..d5b6603 100644 --- a/src/assertions/comparative.typ +++ b/src/assertions/comparative.typ @@ -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), ) } \ No newline at end of file diff --git a/src/assertions/length.typ b/src/assertions/length.typ index b79ea1f..fd37025 100644 --- a/src/assertions/length.typ +++ b/src/assertions/length.typ @@ -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), ) } \ No newline at end of file