diff options
| author | Gemini Lasswell | 2018-06-15 10:23:58 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-08-03 08:53:01 -0700 |
| commit | eba16e5e5829c244d313101a769d4988946387d9 (patch) | |
| tree | 33b098f6324ce3f5feefa5213403789b29527943 /test | |
| parent | e65ec81fc3e556719fae8d8b4b42f571c7e9f4fc (diff) | |
| download | emacs-eba16e5e5829c244d313101a769d4988946387d9.tar.gz emacs-eba16e5e5829c244d313101a769d4988946387d9.zip | |
Support ellipsis expansion in cl-print
* lisp/emacs-lisp/cl-print.el (cl-print-object-contents): New
generic method.
(cl-print-object-contents) <cons, vector,cl-structure-object>: New
methods.
(cl-print-object) <cons>: Use cl-print-insert-ellipsis.
(cl-print-object) <vector, cl-structure-object>: Elide whole object if
print-level exceeded. Use cl-print-insert-ellipsis.
(cl-print-insert-ellipsis, cl-print-propertize-ellipsis)
(cl-print-expand-ellipsis): New functions.
* test/lisp/emacs-lisp/cl-print-tests.el (cl-print-tests-4): Test
printing of objects nested in other objects.
(cl-print-tests-strings, cl-print-tests-ellipsis-cons)
(cl-print-tests-ellipsis-vector, cl-print-tests-ellipsis-struct)
(cl-print-tests-ellipsis-circular): New tests.
(cl-print-tests-check-ellipsis-expansion)
(cl-print-tests-check-ellipsis-expansion-rx): New functions.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/cl-print-tests.el | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el index 404d323d0c1..2b5eb3402bf 100644 --- a/test/lisp/emacs-lisp/cl-print-tests.el +++ b/test/lisp/emacs-lisp/cl-print-tests.el | |||
| @@ -64,11 +64,15 @@ | |||
| 64 | 64 | ||
| 65 | (ert-deftest cl-print-tests-4 () | 65 | (ert-deftest cl-print-tests-4 () |
| 66 | "CL printing observes `print-level'." | 66 | "CL printing observes `print-level'." |
| 67 | (let ((deep-list '(a (b (c (d (e)))))) | 67 | (let* ((deep-list '(a (b (c (d (e)))))) |
| 68 | (deep-struct (cl-print-tests-con)) | 68 | (buried-vector '(a (b (c (d [e]))))) |
| 69 | (print-level 4)) | 69 | (deep-struct (cl-print-tests-con)) |
| 70 | (buried-struct `(a (b (c (d ,deep-struct))))) | ||
| 71 | (print-level 4)) | ||
| 70 | (setf (cl-print-tests-struct-a deep-struct) deep-list) | 72 | (setf (cl-print-tests-struct-a deep-struct) deep-list) |
| 71 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string deep-list))) | 73 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string deep-list))) |
| 74 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string buried-vector))) | ||
| 75 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string buried-struct))) | ||
| 72 | (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)" | 76 | (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)" |
| 73 | (cl-prin1-to-string deep-struct))))) | 77 | (cl-prin1-to-string deep-struct))))) |
| 74 | 78 | ||
| @@ -82,6 +86,85 @@ | |||
| 82 | (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))" | 86 | (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))" |
| 83 | (cl-prin1-to-string quoted-stuff)))))) | 87 | (cl-prin1-to-string quoted-stuff)))))) |
| 84 | 88 | ||
| 89 | (ert-deftest cl-print-tests-ellipsis-cons () | ||
| 90 | "Ellipsis expansion works in conses." | ||
| 91 | (let ((print-length 4) | ||
| 92 | (print-level 3)) | ||
| 93 | (cl-print-tests-check-ellipsis-expansion | ||
| 94 | '(0 1 2 3 4 5) "(0 1 2 3 ...)" "4 5") | ||
| 95 | (cl-print-tests-check-ellipsis-expansion | ||
| 96 | '(0 1 2 3 4 5 6 7 8 9) "(0 1 2 3 ...)" "4 5 6 7 ...") | ||
| 97 | (cl-print-tests-check-ellipsis-expansion | ||
| 98 | '(a (b (c (d (e))))) "(a (b (c ...)))" "(d (e))") | ||
| 99 | (cl-print-tests-check-ellipsis-expansion | ||
| 100 | (let ((x (make-list 6 'b))) | ||
| 101 | (setf (nthcdr 6 x) 'c) | ||
| 102 | x) | ||
| 103 | "(b b b b ...)" "b b . c"))) | ||
| 104 | |||
| 105 | (ert-deftest cl-print-tests-ellipsis-vector () | ||
| 106 | "Ellipsis expansion works in vectors." | ||
| 107 | (let ((print-length 4) | ||
| 108 | (print-level 3)) | ||
| 109 | (cl-print-tests-check-ellipsis-expansion | ||
| 110 | [0 1 2 3 4 5] "[0 1 2 3 ...]" "4 5") | ||
| 111 | (cl-print-tests-check-ellipsis-expansion | ||
| 112 | [0 1 2 3 4 5 6 7 8 9] "[0 1 2 3 ...]" "4 5 6 7 ...") | ||
| 113 | (cl-print-tests-check-ellipsis-expansion | ||
| 114 | [a [b [c [d [e]]]]] "[a [b [c ...]]]" "[d [e]]"))) | ||
| 115 | |||
| 116 | (ert-deftest cl-print-tests-ellipsis-struct () | ||
| 117 | "Ellipsis expansion works in structures." | ||
| 118 | (let ((print-length 4) | ||
| 119 | (print-level 3) | ||
| 120 | (struct (cl-print-tests-con))) | ||
| 121 | (cl-print-tests-check-ellipsis-expansion | ||
| 122 | struct "#s(cl-print-tests-struct :a nil :b nil :c nil :d nil ...)" ":e nil") | ||
| 123 | (let ((print-length 2)) | ||
| 124 | (cl-print-tests-check-ellipsis-expansion | ||
| 125 | struct "#s(cl-print-tests-struct :a nil :b nil ...)" ":c nil :d nil ...")) | ||
| 126 | (cl-print-tests-check-ellipsis-expansion | ||
| 127 | `(a (b (c ,struct))) | ||
| 128 | "(a (b (c ...)))" | ||
| 129 | "#s(cl-print-tests-struct :a nil :b nil :c nil :d nil ...)"))) | ||
| 130 | |||
| 131 | (ert-deftest cl-print-tests-ellipsis-circular () | ||
| 132 | "Ellipsis expansion works with circular objects." | ||
| 133 | (let ((wide-obj (list 0 1 2 3 4)) | ||
| 134 | (deep-obj `(0 (1 (2 (3 (4)))))) | ||
| 135 | (print-length 4) | ||
| 136 | (print-level 3)) | ||
| 137 | (setf (nth 4 wide-obj) wide-obj) | ||
| 138 | (setf (car (cadadr (cadadr deep-obj))) deep-obj) | ||
| 139 | (let ((print-circle nil)) | ||
| 140 | (cl-print-tests-check-ellipsis-expansion-rx | ||
| 141 | wide-obj (regexp-quote "(0 1 2 3 ...)") "\\`#[0-9]\\'") | ||
| 142 | (cl-print-tests-check-ellipsis-expansion-rx | ||
| 143 | deep-obj (regexp-quote "(0 (1 (2 ...)))") "\\`(3 (#[0-9]))\\'")) | ||
| 144 | (let ((print-circle t)) | ||
| 145 | (cl-print-tests-check-ellipsis-expansion | ||
| 146 | wide-obj "#1=(0 1 2 3 ...)" "#1#") | ||
| 147 | (cl-print-tests-check-ellipsis-expansion | ||
| 148 | deep-obj "#1=(0 (1 (2 ...)))" "(3 (#1#))")))) | ||
| 149 | |||
| 150 | (defun cl-print-tests-check-ellipsis-expansion (obj expected expanded) | ||
| 151 | (let* ((result (cl-prin1-to-string obj)) | ||
| 152 | (pos (next-single-property-change 0 'cl-print-ellipsis result)) | ||
| 153 | value) | ||
| 154 | (should pos) | ||
| 155 | (setq value (get-text-property pos 'cl-print-ellipsis result)) | ||
| 156 | (should (equal expected result)) | ||
| 157 | (should (equal expanded (with-output-to-string (cl-print-expand-ellipsis | ||
| 158 | value nil)))))) | ||
| 159 | |||
| 160 | (defun cl-print-tests-check-ellipsis-expansion-rx (obj expected expanded) | ||
| 161 | (let* ((result (cl-prin1-to-string obj)) | ||
| 162 | (pos (next-single-property-change 0 'cl-print-ellipsis result)) | ||
| 163 | (value (get-text-property pos 'cl-print-ellipsis result))) | ||
| 164 | (should (string-match expected result)) | ||
| 165 | (should (string-match expanded (with-output-to-string | ||
| 166 | (cl-print-expand-ellipsis value nil)))))) | ||
| 167 | |||
| 85 | (ert-deftest cl-print-circle () | 168 | (ert-deftest cl-print-circle () |
| 86 | (let ((x '(#1=(a . #1#) #1#))) | 169 | (let ((x '(#1=(a . #1#) #1#))) |
| 87 | (let ((print-circle nil)) | 170 | (let ((print-circle nil)) |