diff options
| author | Nicolas Petton | 2019-03-20 21:44:01 +0100 |
|---|---|---|
| committer | Nicolas Petton | 2019-03-21 21:08:28 +0100 |
| commit | 287cc58f39e9ca8f9ef31b31556f50c25feadaea (patch) | |
| tree | 493af4f9d264395bba72ae15f0afa2162e135839 /test | |
| parent | 093d3e78d21d3d6c718997368ef4b31f9884401c (diff) | |
| download | emacs-287cc58f39e9ca8f9ef31b31556f50c25feadaea.tar.gz emacs-287cc58f39e9ca8f9ef31b31556f50c25feadaea.zip | |
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.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/seq-tests.el | 25 |
1 files changed, 25 insertions, 0 deletions
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. | |||
| 185 | (with-test-sequences (seq '(3 4 5 6)) | 185 | (with-test-sequences (seq '(3 4 5 6)) |
| 186 | (should (= 5 (seq-contains seq 5))))) | 186 | (should (= 5 (seq-contains seq 5))))) |
| 187 | 187 | ||
| 188 | (ert-deftest test-seq-contains-p () | ||
| 189 | (with-test-sequences (seq '(3 4 5 6)) | ||
| 190 | (should (eq (seq-contains-p seq 3) t)) | ||
| 191 | (should-not (seq-contains-p seq 7))) | ||
| 192 | (with-test-sequences (seq '()) | ||
| 193 | (should-not (seq-contains-p seq 3)) | ||
| 194 | (should-not (seq-contains-p seq nil)))) | ||
| 195 | |||
| 196 | (ert-deftest test-seq-contains-p-with-nil () | ||
| 197 | (should (seq-contains-p [nil] nil)) | ||
| 198 | (should (seq-contains-p '(nil) nil))) | ||
| 199 | |||
| 188 | (ert-deftest test-seq-every-p () | 200 | (ert-deftest test-seq-every-p () |
| 189 | (with-test-sequences (seq '(43 54 22 1)) | 201 | (with-test-sequences (seq '(43 54 22 1)) |
| 190 | (should (seq-every-p (lambda (elt) t) seq)) | 202 | (should (seq-every-p (lambda (elt) t) seq)) |
| @@ -436,5 +448,18 @@ Evaluate BODY for each created sequence. | |||
| 436 | (should (equal (seq-rest lst) '(2 3))) | 448 | (should (equal (seq-rest lst) '(2 3))) |
| 437 | (should (equal (seq-rest vec) [2 3])))) | 449 | (should (equal (seq-rest vec) [2 3])))) |
| 438 | 450 | ||
| 451 | ;; Regression tests for bug#34852 | ||
| 452 | (progn | ||
| 453 | (ert-deftest test-seq-intersection-with-nil () | ||
| 454 | (should (equal (seq-intersection '(1 2 nil) '(1 nil)) '(1 nil)))) | ||
| 455 | |||
| 456 | (ert-deftest test-seq-set-equal-p-with-nil () | ||
| 457 | (should (seq-set-equal-p '("a" "b" nil) | ||
| 458 | '(nil "b" "a")))) | ||
| 459 | |||
| 460 | (ert-deftest test-difference-with-nil () | ||
| 461 | (should (equal (seq-difference '(1 nil) '(2 nil)) | ||
| 462 | '(1))))) | ||
| 463 | |||
| 439 | (provide 'seq-tests) | 464 | (provide 'seq-tests) |
| 440 | ;;; seq-tests.el ends here | 465 | ;;; seq-tests.el ends here |