From 287cc58f39e9ca8f9ef31b31556f50c25feadaea Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 20 Mar 2019 21:44:01 +0100 Subject: New seq-contains-p predicate (Bug#34852) * lisp/emacs-lisp/seq.el (seq-contains-p): New predicate function. It is a replacement for seq-contains which cannot be used as a predicate when a sequence contains nil values as it returns the element found. (seq-contains): Make obsolete. * test/lisp/emacs-lisp/seq-tests.el (test-seq-contains-p): (test-seq-intersection-with-nil, test-seq-set-equal-p-with-nil, test-difference-with-nil): Add regression tests. * doc/lispref/sequences.texi (Sequence Functions): Document seq-contains-p. --- test/lisp/emacs-lisp/seq-tests.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index d8f00cfea4c..ef05e2b389d 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -185,6 +185,18 @@ Evaluate BODY for each created sequence. (with-test-sequences (seq '(3 4 5 6)) (should (= 5 (seq-contains seq 5))))) +(ert-deftest test-seq-contains-p () + (with-test-sequences (seq '(3 4 5 6)) + (should (eq (seq-contains-p seq 3) t)) + (should-not (seq-contains-p seq 7))) + (with-test-sequences (seq '()) + (should-not (seq-contains-p seq 3)) + (should-not (seq-contains-p seq nil)))) + +(ert-deftest test-seq-contains-p-with-nil () + (should (seq-contains-p [nil] nil)) + (should (seq-contains-p '(nil) nil))) + (ert-deftest test-seq-every-p () (with-test-sequences (seq '(43 54 22 1)) (should (seq-every-p (lambda (elt) t) seq)) @@ -436,5 +448,18 @@ Evaluate BODY for each created sequence. (should (equal (seq-rest lst) '(2 3))) (should (equal (seq-rest vec) [2 3])))) +;; Regression tests for bug#34852 +(progn + (ert-deftest test-seq-intersection-with-nil () + (should (equal (seq-intersection '(1 2 nil) '(1 nil)) '(1 nil)))) + + (ert-deftest test-seq-set-equal-p-with-nil () + (should (seq-set-equal-p '("a" "b" nil) + '(nil "b" "a")))) + + (ert-deftest test-difference-with-nil () + (should (equal (seq-difference '(1 nil) '(2 nil)) + '(1))))) + (provide 'seq-tests) ;;; seq-tests.el ends here -- cgit v1.2.1