diff options
| author | Tino Calancha | 2017-02-27 16:32:10 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-02-27 16:32:10 +0900 |
| commit | 4daca38d5c673c5b6862e10cfade9559852cce12 (patch) | |
| tree | f50e54581adcb9d69f5d927dec55ba2e13ed63bc /test | |
| parent | 841e3e377c97142cfe76b9d91467f439198f5e39 (diff) | |
| download | emacs-4daca38d5c673c5b6862e10cfade9559852cce12.tar.gz emacs-4daca38d5c673c5b6862e10cfade9559852cce12.zip | |
Prevent for consing in cl-mapc and cl-mapl
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many): Add optional arg ACC;
If non-nil, accumulate values in the result (Bug#25826).
(cl-mapc): Do computations inside function instead of call cl-map.
(cl-mapl): Do computations inside function instead of call cl-maplist.
* lisp/emacs-lisp/cl-lib.el (mapcar): Add autoload cookie.
Call cl--mapcar-many with non-nil 3rd argument.
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-extra-test-map)
(cl-extra-test-mapc, cl-extra-test-mapcar, cl-extra-test-mapl)
(cl-extra-test-maplist): New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/cl-extra-tests.el | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/cl-extra-tests.el b/test/lisp/emacs-lisp/cl-extra-tests.el index 3e2388acc6f..5b2371e7b95 100644 --- a/test/lisp/emacs-lisp/cl-extra-tests.el +++ b/test/lisp/emacs-lisp/cl-extra-tests.el | |||
| @@ -35,4 +35,63 @@ | |||
| 35 | (should (eq (cl-getf plist 'y :none) nil)) | 35 | (should (eq (cl-getf plist 'y :none) nil)) |
| 36 | (should (eq (cl-getf plist 'z :none) :none)))) | 36 | (should (eq (cl-getf plist 'z :none) :none)))) |
| 37 | 37 | ||
| 38 | (ert-deftest cl-extra-test-mapc () | ||
| 39 | (let ((lst '(a b c)) | ||
| 40 | (lst2 '(d e f)) | ||
| 41 | (lst3 '(1 2 3)) | ||
| 42 | (fn1 (lambda (_x) nil)) | ||
| 43 | (fn2 (lambda (_x _y) nil)) | ||
| 44 | (fn3 (lambda (_x _y _z) nil))) | ||
| 45 | (should (equal lst (cl-mapc fn1 lst))) | ||
| 46 | (should (equal lst (cl-mapc fn2 lst lst2))) | ||
| 47 | (should (equal lst (cl-mapc fn3 lst lst2 lst3))))) | ||
| 48 | |||
| 49 | (ert-deftest cl-extra-test-mapl () | ||
| 50 | (let ((lst '(a b c)) | ||
| 51 | (lst2 '(d e f)) | ||
| 52 | (lst3 '(1 2 3)) | ||
| 53 | (fn1 (lambda (x) (should (consp x)))) | ||
| 54 | (fn2 (lambda (x y) (should (and (consp x) (consp y))))) | ||
| 55 | (fn3 (lambda (x y z) (should (and (consp x) (consp y) (consp z)))))) | ||
| 56 | (should (equal lst (cl-mapl fn1 lst))) | ||
| 57 | (should (equal lst (cl-mapl fn2 lst lst2))) | ||
| 58 | (should (equal lst (cl-mapl fn3 lst lst2 lst3))))) | ||
| 59 | |||
| 60 | (ert-deftest cl-extra-test-mapcar () | ||
| 61 | (let ((lst '(a b c)) | ||
| 62 | (lst2 '(d e f)) | ||
| 63 | (lst3 '(1 2 3)) | ||
| 64 | (fn1 (lambda (x) x)) | ||
| 65 | (fn2 (lambda (_x y) y)) | ||
| 66 | (fn3 (lambda (_x _y z) z))) | ||
| 67 | (should (equal lst (cl-mapcar fn1 lst))) | ||
| 68 | (should (equal lst2 (cl-mapcar fn2 lst lst2))) | ||
| 69 | (should (equal lst3 (cl-mapcar fn3 lst lst2 lst3))))) | ||
| 70 | |||
| 71 | (ert-deftest cl-extra-test-map () | ||
| 72 | (let ((lst '(a b c)) | ||
| 73 | (lst2 '(d e f)) | ||
| 74 | (lst3 '(1 2 3)) | ||
| 75 | (fn1 (lambda (x) x)) | ||
| 76 | (fn2 (lambda (_x y) y)) | ||
| 77 | (fn3 (lambda (x _y _z) (string-to-char (format "%S" x))))) | ||
| 78 | (should (equal lst (cl-map 'list fn1 lst))) | ||
| 79 | (should (equal (vconcat lst2) (cl-map 'vector fn2 lst lst2))) | ||
| 80 | (should (equal (mapconcat (lambda (x) (format "%S" x)) lst "") | ||
| 81 | (cl-map 'string fn3 lst lst2 lst3))))) | ||
| 82 | |||
| 83 | (ert-deftest cl-extra-test-maplist () | ||
| 84 | (let ((lst '(a b c)) | ||
| 85 | (lst2 '(d e f)) | ||
| 86 | (lst3 '(1 2 3)) | ||
| 87 | (fn1 (lambda (x) (should (consp x)) x)) | ||
| 88 | (fn2 (lambda (x y) (should (and (consp x) (consp y))) y)) | ||
| 89 | (fn3 (lambda (x y z) (should (and (consp x) (consp y) (consp z))) z))) | ||
| 90 | (should (equal (list lst (cdr lst) (cddr lst)) | ||
| 91 | (cl-maplist fn1 lst))) | ||
| 92 | (should (equal (list lst2 (cdr lst2) (cddr lst2)) | ||
| 93 | (cl-maplist fn2 lst lst2))) | ||
| 94 | (should (equal (list lst3 (cdr lst3) (cddr lst3)) | ||
| 95 | (cl-maplist fn3 lst lst2 lst3))))) | ||
| 96 | |||
| 38 | ;;; cl-extra-tests.el ends here | 97 | ;;; cl-extra-tests.el ends here |