diff options
| author | Gemini Lasswell | 2018-06-15 10:26:13 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-08-03 08:53:02 -0700 |
| commit | 8a7620955b4d859caecd9a5dc9f2a986baf994fd (patch) | |
| tree | b0749d1815b471e881579d6483cf0684089ff4a5 /test | |
| parent | eba16e5e5829c244d313101a769d4988946387d9 (diff) | |
| download | emacs-8a7620955b4d859caecd9a5dc9f2a986baf994fd.tar.gz emacs-8a7620955b4d859caecd9a5dc9f2a986baf994fd.zip | |
Add methods for strings to cl-print
* lisp/emacs-lisp/cl-print.el (cl-print-object) <string>: New method.
(cl-print-object-contents) <string>: New method.
(cl-print--find-sharing): Look in string property lists.
* test/lisp/emacs-lisp/cl-print-tests.el (cl-print-tests-3): Test
printing of long strings.
(cl-print-tests-4): Test printing of strings nested in other objects.
(cl-print-tests-strings, cl-print-tests-ellipsis-string): New
tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/cl-print-tests.el | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el index 2b5eb3402bf..7594d2466b5 100644 --- a/test/lisp/emacs-lisp/cl-print-tests.el +++ b/test/lisp/emacs-lisp/cl-print-tests.el | |||
| @@ -56,11 +56,13 @@ | |||
| 56 | (let ((long-list (make-list 5 'a)) | 56 | (let ((long-list (make-list 5 'a)) |
| 57 | (long-vec (make-vector 5 'b)) | 57 | (long-vec (make-vector 5 'b)) |
| 58 | (long-struct (cl-print-tests-con)) | 58 | (long-struct (cl-print-tests-con)) |
| 59 | (long-string (make-string 5 ?a)) | ||
| 59 | (print-length 4)) | 60 | (print-length 4)) |
| 60 | (should (equal "(a a a a ...)" (cl-prin1-to-string long-list))) | 61 | (should (equal "(a a a a ...)" (cl-prin1-to-string long-list))) |
| 61 | (should (equal "[b b b b ...]" (cl-prin1-to-string long-vec))) | 62 | (should (equal "[b b b b ...]" (cl-prin1-to-string long-vec))) |
| 62 | (should (equal "#s(cl-print-tests-struct :a nil :b nil :c nil :d nil ...)" | 63 | (should (equal "#s(cl-print-tests-struct :a nil :b nil :c nil :d nil ...)" |
| 63 | (cl-prin1-to-string long-struct))))) | 64 | (cl-prin1-to-string long-struct))) |
| 65 | (should (equal "\"aaaa...\"" (cl-prin1-to-string long-string))))) | ||
| 64 | 66 | ||
| 65 | (ert-deftest cl-print-tests-4 () | 67 | (ert-deftest cl-print-tests-4 () |
| 66 | "CL printing observes `print-level'." | 68 | "CL printing observes `print-level'." |
| @@ -68,11 +70,16 @@ | |||
| 68 | (buried-vector '(a (b (c (d [e]))))) | 70 | (buried-vector '(a (b (c (d [e]))))) |
| 69 | (deep-struct (cl-print-tests-con)) | 71 | (deep-struct (cl-print-tests-con)) |
| 70 | (buried-struct `(a (b (c (d ,deep-struct))))) | 72 | (buried-struct `(a (b (c (d ,deep-struct))))) |
| 73 | (buried-string '(a (b (c (d #("hello" 0 5 (cl-print-test t))))))) | ||
| 74 | (buried-simple-string '(a (b (c (d "hello"))))) | ||
| 71 | (print-level 4)) | 75 | (print-level 4)) |
| 72 | (setf (cl-print-tests-struct-a deep-struct) deep-list) | 76 | (setf (cl-print-tests-struct-a deep-struct) deep-list) |
| 73 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string deep-list))) | 77 | (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))) | 78 | (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))) | 79 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string buried-struct))) |
| 80 | (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string buried-string))) | ||
| 81 | (should (equal "(a (b (c (d \"hello\"))))" | ||
| 82 | (cl-prin1-to-string buried-simple-string))) | ||
| 76 | (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)" | 83 | (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)" |
| 77 | (cl-prin1-to-string deep-struct))))) | 84 | (cl-prin1-to-string deep-struct))))) |
| 78 | 85 | ||
| @@ -86,6 +93,35 @@ | |||
| 86 | (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))" | 93 | (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))" |
| 87 | (cl-prin1-to-string quoted-stuff)))))) | 94 | (cl-prin1-to-string quoted-stuff)))))) |
| 88 | 95 | ||
| 96 | (ert-deftest cl-print-tests-strings () | ||
| 97 | "CL printing prints strings and propertized strings." | ||
| 98 | (let* ((str1 "abcdefghij") | ||
| 99 | (str2 #("abcdefghij" 3 6 (bold t) 7 9 (italic t))) | ||
| 100 | (str3 #("abcdefghij" 0 10 (test t))) | ||
| 101 | (obj '(a b)) | ||
| 102 | ;; Since the byte compiler reuses string literals, | ||
| 103 | ;; and the put-text-property call is destructive, use | ||
| 104 | ;; copy-sequence to make a new string. | ||
| 105 | (str4 (copy-sequence "abcdefghij"))) | ||
| 106 | (put-text-property 0 5 'test obj str4) | ||
| 107 | (put-text-property 7 10 'test obj str4) | ||
| 108 | |||
| 109 | (should (equal "\"abcdefghij\"" (cl-prin1-to-string str1))) | ||
| 110 | (should (equal "#(\"abcdefghij\" 3 6 (bold t) 7 9 (italic t))" | ||
| 111 | (cl-prin1-to-string str2))) | ||
| 112 | (should (equal "#(\"abcdefghij\" 0 10 (test t))" | ||
| 113 | (cl-prin1-to-string str3))) | ||
| 114 | (let ((print-circle nil)) | ||
| 115 | (should | ||
| 116 | (equal | ||
| 117 | "#(\"abcdefghij\" 0 5 (test (a b)) 7 10 (test (a b)))" | ||
| 118 | (cl-prin1-to-string str4)))) | ||
| 119 | (let ((print-circle t)) | ||
| 120 | (should | ||
| 121 | (equal | ||
| 122 | "#(\"abcdefghij\" 0 5 (test #1=(a b)) 7 10 (test #1#))" | ||
| 123 | (cl-prin1-to-string str4)))))) | ||
| 124 | |||
| 89 | (ert-deftest cl-print-tests-ellipsis-cons () | 125 | (ert-deftest cl-print-tests-ellipsis-cons () |
| 90 | "Ellipsis expansion works in conses." | 126 | "Ellipsis expansion works in conses." |
| 91 | (let ((print-length 4) | 127 | (let ((print-length 4) |
| @@ -113,6 +149,21 @@ | |||
| 113 | (cl-print-tests-check-ellipsis-expansion | 149 | (cl-print-tests-check-ellipsis-expansion |
| 114 | [a [b [c [d [e]]]]] "[a [b [c ...]]]" "[d [e]]"))) | 150 | [a [b [c [d [e]]]]] "[a [b [c ...]]]" "[d [e]]"))) |
| 115 | 151 | ||
| 152 | (ert-deftest cl-print-tests-ellipsis-string () | ||
| 153 | "Ellipsis expansion works in strings." | ||
| 154 | (let ((print-length 4) | ||
| 155 | (print-level 3)) | ||
| 156 | (cl-print-tests-check-ellipsis-expansion | ||
| 157 | "abcdefg" "\"abcd...\"" "efg") | ||
| 158 | (cl-print-tests-check-ellipsis-expansion | ||
| 159 | "abcdefghijk" "\"abcd...\"" "efgh...") | ||
| 160 | (cl-print-tests-check-ellipsis-expansion | ||
| 161 | '(1 (2 (3 #("abcde" 0 5 (test t))))) | ||
| 162 | "(1 (2 (3 ...)))" "#(\"abcd...\" 0 5 (test t))") | ||
| 163 | (cl-print-tests-check-ellipsis-expansion | ||
| 164 | #("abcd" 0 1 (bold t) 1 2 (invisible t) 3 4 (italic t)) | ||
| 165 | "#(\"abcd\" 0 1 (bold t) ...)" "1 2 (invisible t) ..."))) | ||
| 166 | |||
| 116 | (ert-deftest cl-print-tests-ellipsis-struct () | 167 | (ert-deftest cl-print-tests-ellipsis-struct () |
| 117 | "Ellipsis expansion works in structures." | 168 | "Ellipsis expansion works in structures." |
| 118 | (let ((print-length 4) | 169 | (let ((print-length 4) |