]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/seq/tests/seq-tests.el
Split seq.el into separate files for different versions of Emacs
[gnu-emacs-elpa] / packages / seq / tests / seq-tests.el
index 3643ce53cb0ca39e2e933045160ae4f47e421629..cd9c213640357f8f85c2c169c3354dd7e541a828 100644 (file)
@@ -22,7 +22,7 @@
 
 ;;; Commentary:
 
-;; Tests for sequences.el
+;; Tests for seq.el
 
 ;;; Code:
 
@@ -92,6 +92,16 @@ Evaluate BODY for each created sequence.
   (with-test-sequences (seq '())
     (should (seq-empty-p (seq-take-while #'test-sequences-oddp seq)))))
 
+(ert-deftest test-seq-map-indexed ()
+  (should (equal (seq-map-indexed (lambda (elt i)
+                                    (list elt i))
+                                  nil)
+                 nil))
+  (should (equal (seq-map-indexed (lambda (elt i)
+                                    (list elt i))
+                                  '(a b c d))
+                 '((a 0) (b 1) (c 2) (d 3)))))
+
 (ert-deftest test-seq-filter ()
   (with-test-sequences (seq '(6 7 8 9 10))
     (should (equal (seq-filter #'test-sequences-evenp seq) '(6 8 10)))
@@ -124,21 +134,32 @@ Evaluate BODY for each created sequence.
     (should (eq (seq-reduce #'+ seq 0) 0))
     (should (eq (seq-reduce #'+ seq 7) 7))))
 
-(ert-deftest test-seq-some-p ()
+(ert-deftest test-seq-some ()
   (with-test-sequences (seq '(4 3 2 1))
-    (should (= (seq-some-p #'test-sequences-evenp seq) 4))
-    (should (= (seq-some-p #'test-sequences-oddp seq) 3))
-    (should-not (seq-some-p (lambda (elt) (> elt 10)) seq)))
+    (should (seq-some #'test-sequences-evenp seq))
+    (should (seq-some #'test-sequences-oddp seq))
+    (should-not (seq-some (lambda (elt) (> elt 10)) seq)))
   (with-test-sequences (seq '())
-    (should-not (seq-some-p #'test-sequences-oddp seq))))
+    (should-not (seq-some #'test-sequences-oddp seq)))
+  (should (seq-some #'null '(1 nil 2))))
 
-(ert-deftest test-seq-contains-p ()
+(ert-deftest test-seq-find ()
+  (with-test-sequences (seq '(4 3 2 1))
+    (should (= 4 (seq-find #'test-sequences-evenp seq)))
+    (should (= 3 (seq-find #'test-sequences-oddp seq)))
+    (should-not (seq-find (lambda (elt) (> elt 10)) seq)))
+  (should-not (seq-find #'null '(1 nil 2)))
+  (should-not (seq-find #'null '(1 nil 2) t))
+  (should-not (seq-find #'null '(1 2 3)))
+  (should (seq-find #'null '(1 2 3) 'sentinel)))
+
+(ert-deftest test-seq-contains ()
   (with-test-sequences (seq '(3 4 5 6))
-    (should (seq-contains-p seq 3))
-    (should-not (seq-contains-p seq 7)))
+    (should (seq-contains seq 3))
+    (should-not (seq-contains seq 7)))
   (with-test-sequences (seq '())
-    (should-not (seq-contains-p seq 3))
-    (should-not (seq-contains-p seq nil))))
+    (should-not (seq-contains seq 3))
+    (should-not (seq-contains seq nil))))
 
 (ert-deftest test-seq-every-p ()
   (with-test-sequences (seq '(43 54 22 1))
@@ -302,5 +323,27 @@ Evaluate BODY for each created sequence.
     (should (= (seq-min seq) 0))
     (should (= (seq-max seq) 5))))
 
+(ert-deftest test-seq-position ()
+  (with-test-sequences (seq '(2 4 6))
+    (should (null (seq-position seq 1)))
+    (should (= (seq-position seq 4) 1)))
+  (let ((seq '(a b c)))
+    (should (null (seq-position seq 'd #'eq)))
+    (should (= (seq-position seq 'a #'eq) 0))
+    (should (null (seq-position seq (make-symbol "a") #'eq)))))
+
+(ert-deftest test-seq-mapn ()
+  (should-error (seq-mapn #'identity))
+  (with-test-sequences (seq '(1 2 3 4 5 6 7))
+    (should (equal (append seq nil)
+                   (seq-mapn #'identity seq)))
+    (should (equal (seq-mapn #'1+ seq)
+                   (seq-map #'1+ seq)))
+
+    (with-test-sequences (seq-2 '(10 20 30 40 50))
+      (should (equal (seq-mapn #'+ seq seq-2)
+                     '(11 22 33 44 55)))
+      (should (equal (seq-mapn #'+ seq seq-2 nil) nil)))))
+
 (provide 'seq-tests)
 ;;; seq-tests.el ends here