From 886b758b74e077048abcf3a784acf5fd9387d4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Pospi=CC=81s=CC=8Cil?= Date: Tue, 13 Dec 2022 09:11:52 +0100 Subject: [PATCH] Add asserted point --- eleanor/points.janet | 11 ++++++++--- test/suite01.janet | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/eleanor/points.janet b/eleanor/points.janet index 4a0c5c8..d668333 100644 --- a/eleanor/points.janet +++ b/eleanor/points.janet @@ -164,9 +164,9 @@ Returns function that will remove `value` from the array base. ``` [value] - (fn remove [arr] - (def index (find-index |(deep= value $) arr)) - (array/remove arr index))) + (fn remove [base] + (def index (find-index |(deep= value $) base)) + (array/remove base index))) (defn trace-base ``` @@ -300,3 +300,8 @@ (def <-> "Alias to collected-to-base" collected->base) + +(defn asserted + "Asserts `pred` on the `base` and errors with `msg` if it fails." + [pred msg] + (fn [base] (assert (pred base) msg))) diff --git a/test/suite01.janet b/test/suite01.janet index e6fb1d0..8c629d0 100644 --- a/test/suite01.janet +++ b/test/suite01.janet @@ -402,4 +402,6 @@ (assert (deep= @[@[0] 0] ((=> (<- first) <->) (range 10))) "collected->base") +(assert-error "asserted" ((=> (asserted nil? "must be nil")) true)) + (end-suite) -- 2.38.5