branch: externals/compat
commit 8ab4272a5d0e3ba613e201681457c06745356e2e
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
Add thread-first and thread-last tests
---
compat-25.el | 4 ++--
compat-tests.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/compat-25.el b/compat-25.el
index 9ad856f39d..1a01b57fb8 100644
--- a/compat-25.el
+++ b/compat-25.el
@@ -176,7 +176,7 @@ The variable list SPEC is the same as in `if-let'."
;;;; Defined in subr-x.el
-(compat-defmacro thread-first (&rest forms) ;; <UNTESTED>
+(compat-defmacro thread-first (&rest forms) ;; <OK>
"Thread FORMS elements as the first argument of their successor.
Example:
(thread-first
@@ -200,7 +200,7 @@ threading."
(cdr form))))
body))
-(compat-defmacro thread-last (&rest forms) ;; <UNTESTED>
+(compat-defmacro thread-last (&rest forms) ;; <OK>
"Thread FORMS elements as the last argument of their successor.
Example:
(thread-last
diff --git a/compat-tests.el b/compat-tests.el
index 2beb7a3c34..41e25bc5fb 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -46,6 +46,36 @@
(defmacro should-equal (a b)
`(should (equal ,a ,b)))
+(ert-deftest thread-first ()
+ (should-equal (thread-first (+ 40 2)) 42)
+ (should-equal (thread-first
+ 5
+ (+ 20)
+ (/ 25)
+ -
+ (+ 40)) 39)
+ (should-equal (thread-first
+ "this-is-a-string"
+ (split-string "-")
+ (nbutlast 2)
+ (append (list "good")))
+ (list "this" "is" "good")))
+
+(ert-deftest thread-last ()
+ (should-equal (thread-last (+ 40 2)) 42)
+ (should-equal (thread-last
+ 5
+ (+ 20)
+ (/ 25)
+ -
+ (+ 40)) 39)
+ (should-equal (thread-last
+ (list 1 -2 3 -4 5)
+ (mapcar #'abs)
+ (cl-reduce #'+)
+ (format "abs sum is: %s"))
+ "abs sum is: 15"))
+
(ert-deftest ntake ()
(should-not (ntake 5 nil))
(should-equal '(1 2) (ntake 5 '(1 2)))