From a98f60654ce831844ad232966b81ce65c0d5bf64 Mon Sep 17 00:00:00 2001 From: James R Swift Date: Wed, 24 Jul 2024 14:10:57 +0100 Subject: [PATCH 1/4] Add negated equality assertions --- src/assertions/comparative.typ | 10 ++++++++++ src/assertions/length.typ | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/assertions/comparative.typ b/src/assertions/comparative.typ index 5ecb8bd..423620b 100644 --- a/src/assertions/comparative.typ +++ b/src/assertions/comparative.typ @@ -28,4 +28,14 @@ condition: (self, it) => it == rhs, message: (self, it) => "Must be exactly " + str(rhs), ) +} + +/// Asserts that tested value is not exactly equal to argument +#let eq(rhs) = { + assert-positive-type(rhs, types: (int,), name: "Equality") + + return ( + condition: (self, it) => it != rhs, + message: (self, it) => "Must not equal " + str(rhs), + ) } \ No newline at end of file diff --git a/src/assertions/length.typ b/src/assertions/length.typ index b79ea1f..cf75a11 100644 --- a/src/assertions/length.typ +++ b/src/assertions/length.typ @@ -28,4 +28,14 @@ condition: (self, it) => it.len() == rhs, message: (self, it) => "Length must equal " + str(rhs), ) +} + +/// Asserts that tested value's length is not equal to argument +#let equals(rhs) = { + assert-positive-type(rhs, 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 From b0c9ba46f4d13a6c0e0b7a277b46754d867398de Mon Sep 17 00:00:00 2001 From: James R Swift Date: Wed, 24 Jul 2024 14:11:41 +0100 Subject: [PATCH 2/4] amend changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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 From f982f00521ddcca9e13ca81fee7f280bfa3975ea Mon Sep 17 00:00:00 2001 From: James R Swift Date: Wed, 24 Jul 2024 14:12:45 +0100 Subject: [PATCH 3/4] update exports and function names --- src/assertions.typ | 2 +- src/assertions/comparative.typ | 2 +- src/assertions/length.typ | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 423620b..eea1192 100644 --- a/src/assertions/comparative.typ +++ b/src/assertions/comparative.typ @@ -31,7 +31,7 @@ } /// Asserts that tested value is not exactly equal to argument -#let eq(rhs) = { +#let neq(rhs) = { assert-positive-type(rhs, types: (int,), name: "Equality") return ( diff --git a/src/assertions/length.typ b/src/assertions/length.typ index cf75a11..fc824a0 100644 --- a/src/assertions/length.typ +++ b/src/assertions/length.typ @@ -31,7 +31,7 @@ } /// Asserts that tested value's length is not equal to argument -#let equals(rhs) = { +#let neq(rhs) = { assert-positive-type(rhs, types: (int,), name: "Exact length") return ( From d7457952f89d3719299e037e2e71f34fd127221a Mon Sep 17 00:00:00 2001 From: James R Swift Date: Wed, 24 Jul 2024 19:44:33 +0100 Subject: [PATCH 4/4] rename eq and neq argument to arg --- src/assertions/comparative.typ | 16 ++++++++-------- src/assertions/length.typ | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/assertions/comparative.typ b/src/assertions/comparative.typ index eea1192..d5b6603 100644 --- a/src/assertions/comparative.typ +++ b/src/assertions/comparative.typ @@ -21,21 +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(rhs) = { - assert-positive-type(rhs, types: (int,), name: "Equality") +#let neq(arg) = { + assert-positive-type(arg, types: (int,), name: "Equality") return ( - condition: (self, it) => it != rhs, - message: (self, it) => "Must not equal " + str(rhs), + 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 fc824a0..fd37025 100644 --- a/src/assertions/length.typ +++ b/src/assertions/length.typ @@ -21,18 +21,18 @@ } /// 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(rhs) = { - assert-positive-type(rhs, types: (int,), name: "Exact length") +#let neq(arg) = { + assert-positive-type(arg, types: (int,), name: "Exact length") return ( condition: (self, it) => it.len() != rhs,