diff options
| author | Basil L. Contovounesios | 2018-07-09 18:46:33 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-07-09 19:00:43 -0700 |
| commit | 2fde6275b69fd113e78243790bf112bbdd2fe2bf (patch) | |
| tree | f28a04fdabc51d275689066b41b9149422d9f3cb /test | |
| parent | e4ad2d1a8fad8c8c786b61083b05cfaa1ea5669c (diff) | |
| download | emacs-2fde6275b69fd113e78243790bf112bbdd2fe2bf.tar.gz emacs-2fde6275b69fd113e78243790bf112bbdd2fe2bf.zip | |
Add predicate proper-list-p
For discussion, see emacs-devel thread starting at
https://lists.gnu.org/archive/html/emacs-devel/2018-04/msg00460.html.
* lisp/subr.el (proper-list-p): New function.
Implementation suggested by Paul Eggert <eggert@cs.ucla.edu> in
https://lists.gnu.org/archive/html/emacs-devel/2018-06/msg00138.html.
* doc/lispref/lists.texi (List Elements):
* etc/NEWS: Document proper-list-p.
* lisp/org/ob-core.el (org-babel-insert-result):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-if):
* lisp/emacs-lisp/cl-macs.el (cl--make-usage-args): Use proper-list-p.
* lisp/emacs-lisp/ert.el (ert--proper-list-p): Remove.
Replaced by proper-list-p in lisp/subr.el.
(ert--explain-equal-rec): Use proper-list-length.
* lisp/format.el (format-proper-list-p): Remove.
Replaced by proper-list-p in lisp/subr.el.
(format-annotate-single-property-change): Use proper-list-p.
* test/lisp/emacs-lisp/ert-tests.el (ert-test-proper-list-p):
Move from here...
* test/lisp/subr-tests.el (subr-tests--proper-list-length):
...to here, mutatis mutandis.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/ert-tests.el | 42 | ||||
| -rw-r--r-- | test/lisp/subr-tests.el | 18 |
2 files changed, 18 insertions, 42 deletions
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el index e92b4342748..cb957bd9fd6 100644 --- a/test/lisp/emacs-lisp/ert-tests.el +++ b/test/lisp/emacs-lisp/ert-tests.el | |||
| @@ -496,48 +496,6 @@ This macro is used to test if macroexpansion in `should' works." | |||
| 496 | 496 | ||
| 497 | 497 | ||
| 498 | ;;; Tests for utility functions. | 498 | ;;; Tests for utility functions. |
| 499 | (ert-deftest ert-test-proper-list-p () | ||
| 500 | (should (ert--proper-list-p '())) | ||
| 501 | (should (ert--proper-list-p '(1))) | ||
| 502 | (should (ert--proper-list-p '(1 2))) | ||
| 503 | (should (ert--proper-list-p '(1 2 3))) | ||
| 504 | (should (ert--proper-list-p '(1 2 3 4))) | ||
| 505 | (should (not (ert--proper-list-p 'a))) | ||
| 506 | (should (not (ert--proper-list-p '(1 . a)))) | ||
| 507 | (should (not (ert--proper-list-p '(1 2 . a)))) | ||
| 508 | (should (not (ert--proper-list-p '(1 2 3 . a)))) | ||
| 509 | (should (not (ert--proper-list-p '(1 2 3 4 . a)))) | ||
| 510 | (let ((a (list 1))) | ||
| 511 | (setf (cdr (last a)) a) | ||
| 512 | (should (not (ert--proper-list-p a)))) | ||
| 513 | (let ((a (list 1 2))) | ||
| 514 | (setf (cdr (last a)) a) | ||
| 515 | (should (not (ert--proper-list-p a)))) | ||
| 516 | (let ((a (list 1 2 3))) | ||
| 517 | (setf (cdr (last a)) a) | ||
| 518 | (should (not (ert--proper-list-p a)))) | ||
| 519 | (let ((a (list 1 2 3 4))) | ||
| 520 | (setf (cdr (last a)) a) | ||
| 521 | (should (not (ert--proper-list-p a)))) | ||
| 522 | (let ((a (list 1 2))) | ||
| 523 | (setf (cdr (last a)) (cdr a)) | ||
| 524 | (should (not (ert--proper-list-p a)))) | ||
| 525 | (let ((a (list 1 2 3))) | ||
| 526 | (setf (cdr (last a)) (cdr a)) | ||
| 527 | (should (not (ert--proper-list-p a)))) | ||
| 528 | (let ((a (list 1 2 3 4))) | ||
| 529 | (setf (cdr (last a)) (cdr a)) | ||
| 530 | (should (not (ert--proper-list-p a)))) | ||
| 531 | (let ((a (list 1 2 3))) | ||
| 532 | (setf (cdr (last a)) (cddr a)) | ||
| 533 | (should (not (ert--proper-list-p a)))) | ||
| 534 | (let ((a (list 1 2 3 4))) | ||
| 535 | (setf (cdr (last a)) (cddr a)) | ||
| 536 | (should (not (ert--proper-list-p a)))) | ||
| 537 | (let ((a (list 1 2 3 4))) | ||
| 538 | (setf (cdr (last a)) (cl-cdddr a)) | ||
| 539 | (should (not (ert--proper-list-p a))))) | ||
| 540 | |||
| 541 | (ert-deftest ert-test-parse-keys-and-body () | 499 | (ert-deftest ert-test-parse-keys-and-body () |
| 542 | (should (equal (ert--parse-keys-and-body '(foo)) '(nil (foo)))) | 500 | (should (equal (ert--parse-keys-and-body '(foo)) '(nil (foo)))) |
| 543 | (should (equal (ert--parse-keys-and-body '(:bar foo)) '((:bar foo) nil))) | 501 | (should (equal (ert--parse-keys-and-body '(:bar foo)) '((:bar foo) nil))) |
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 52b61d9fb97..86938d5dbe0 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el | |||
| @@ -306,6 +306,24 @@ cf. Bug#25477." | |||
| 306 | (should (eq (string-to-char (symbol-name (gensym))) ?g)) | 306 | (should (eq (string-to-char (symbol-name (gensym))) ?g)) |
| 307 | (should (eq (string-to-char (symbol-name (gensym "X"))) ?X))) | 307 | (should (eq (string-to-char (symbol-name (gensym "X"))) ?X))) |
| 308 | 308 | ||
| 309 | (ert-deftest subr-tests--proper-list-p () | ||
| 310 | "Test `proper-list-p' behavior." | ||
| 311 | (dotimes (length 4) | ||
| 312 | ;; Proper and dotted lists. | ||
| 313 | (let ((list (make-list length 0))) | ||
| 314 | (should (= (proper-list-p list) length)) | ||
| 315 | (should (not (proper-list-p (nconc list 0))))) | ||
| 316 | ;; Circular lists. | ||
| 317 | (dotimes (n (1+ length)) | ||
| 318 | (let ((circle (make-list (1+ length) 0))) | ||
| 319 | (should (not (proper-list-p (nconc circle (nthcdr n circle)))))))) | ||
| 320 | ;; Atoms. | ||
| 321 | (should (not (proper-list-p 0))) | ||
| 322 | (should (not (proper-list-p ""))) | ||
| 323 | (should (not (proper-list-p []))) | ||
| 324 | (should (not (proper-list-p (make-bool-vector 0 nil)))) | ||
| 325 | (should (not (proper-list-p (make-symbol "a"))))) | ||
| 326 | |||
| 309 | (ert-deftest subr-tests--assq-delete-all () | 327 | (ert-deftest subr-tests--assq-delete-all () |
| 310 | "Test `assq-delete-all' behavior." | 328 | "Test `assq-delete-all' behavior." |
| 311 | (cl-flet ((new-list-fn | 329 | (cl-flet ((new-list-fn |