aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp
diff options
context:
space:
mode:
authorGemini Lasswell2019-08-04 15:56:12 -0700
committerGemini Lasswell2019-09-13 13:43:07 -0700
commit3bd6ef40b55e429a321c87a09fd94e6ca0e50ae7 (patch)
treeb76524f92d867c0d7a7de186fca01c8cb017cfd1 /test/lisp
parent6eaf39d21b70802e6bc607ee2fc2fff67b79231a (diff)
downloademacs-3bd6ef40b55e429a321c87a09fd94e6ca0e50ae7.tar.gz
emacs-3bd6ef40b55e429a321c87a09fd94e6ca0e50ae7.zip
Create common tests for print.c and cl-print.el
* test/lisp/emacs-lisp/cl-print-tests.el (cl-print--test, cl-print-tests-1, cl-print-tests-2) (cl-print-tests-3, cl-print-tests-4, cl-print-tests-5) (cl-print-tests-strings, cl-print-circle, cl-print-circle-2): Remove. * test/src/print-tests.el (print-tests--prin1-to-string): New alias. (print-tests--deftest): New macro. (print-hex-backslash, print-read-roundtrip, print-bignum): Define with print-tests--deftest and use print-tests--prin1-to-string. (print-tests--prints-with-charset-p): Use print-tests--prin1-to-string. (print-tests--print-charset-text-property-nil) (print-tests--print-charset-text-property-t) (print-tests--print-charset-text-property-default): Define with print-tests--deftest. (print-tests-print-gensym) (print-tests-continuous-numbering, print-tests-1, print-tests-2) (print-tests-3, print-tests-4, print-tests-5) (print-tests-strings, print-circle, print-circle-2): New tests. (print--test, print-tests-struct): New cl-defstructs.
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/emacs-lisp/cl-print-tests.el115
1 files changed, 3 insertions, 112 deletions
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el
index 406c528dce5..31d79df71b5 100644
--- a/test/lisp/emacs-lisp/cl-print-tests.el
+++ b/test/lisp/emacs-lisp/cl-print-tests.el
@@ -19,109 +19,17 @@
19 19
20;;; Commentary: 20;;; Commentary:
21 21
22;; See test/src/print-tests.el for tests which apply to both
23;; cl-print.el and src/print.c.
24
22;;; Code: 25;;; Code:
23 26
24(require 'ert) 27(require 'ert)
25 28
26(cl-defstruct cl-print--test a b)
27
28(ert-deftest cl-print-tests-1 ()
29 "Test cl-print code."
30 (let ((x (make-cl-print--test :a 1 :b 2)))
31 (let ((print-circle nil))
32 (should (equal (cl-prin1-to-string `((x . ,x) (y . ,x)))
33 "((x . #s(cl-print--test :a 1 :b 2)) (y . #s(cl-print--test :a 1 :b 2)))")))
34 (let ((print-circle t))
35 (should (equal (cl-prin1-to-string `((x . ,x) (y . ,x)))
36 "((x . #1=#s(cl-print--test :a 1 :b 2)) (y . #1#))")))
37 (should (string-match "\\`#f(compiled-function (x) \"[^\"]+\" [^)]*)\\'"
38 (cl-prin1-to-string (symbol-function #'caar))))))
39
40(ert-deftest cl-print-tests-2 ()
41 (let ((x (record 'foo 1 2 3)))
42 (should (equal
43 x
44 (car (read-from-string (with-output-to-string (prin1 x))))))
45 (let ((print-circle t))
46 (should (string-match
47 "\\`(#1=#s(foo 1 2 3) #1#)\\'"
48 (cl-prin1-to-string (list x x)))))))
49
50(cl-defstruct (cl-print-tests-struct 29(cl-defstruct (cl-print-tests-struct
51 (:constructor cl-print-tests-con)) 30 (:constructor cl-print-tests-con))
52 a b c d e) 31 a b c d e)
53 32
54(ert-deftest cl-print-tests-3 ()
55 "CL printing observes `print-length'."
56 (let ((long-list (make-list 5 'a))
57 (long-vec (make-vector 5 'b))
58 (long-struct (cl-print-tests-con))
59 (long-string (make-string 5 ?a))
60 (print-length 4))
61 (should (equal "(a a a a ...)" (cl-prin1-to-string long-list)))
62 (should (equal "[b b b b ...]" (cl-prin1-to-string long-vec)))
63 (should (equal "#s(cl-print-tests-struct :a nil :b nil :c nil :d nil ...)"
64 (cl-prin1-to-string long-struct)))
65 (should (equal "\"aaaa...\"" (cl-prin1-to-string long-string)))))
66
67(ert-deftest cl-print-tests-4 ()
68 "CL printing observes `print-level'."
69 (let* ((deep-list '(a (b (c (d (e))))))
70 (buried-vector '(a (b (c (d [e])))))
71 (deep-struct (cl-print-tests-con))
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")))))
75 (print-level 4))
76 (setf (cl-print-tests-struct-a deep-struct) deep-list)
77 (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string deep-list)))
78 (should (equal "(a (b (c (d ...))))" (cl-prin1-to-string buried-vector)))
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)))
83 (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)"
84 (cl-prin1-to-string deep-struct)))))
85
86(ert-deftest cl-print-tests-5 ()
87 "CL printing observes `print-quoted'."
88 (let ((quoted-stuff '('a #'b `(,c ,@d))))
89 (let ((print-quoted t))
90 (should (equal "('a #'b `(,c ,@d))"
91 (cl-prin1-to-string quoted-stuff))))
92 (let ((print-quoted nil))
93 (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))"
94 (cl-prin1-to-string quoted-stuff))))))
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
125(ert-deftest cl-print-tests-ellipsis-cons () 33(ert-deftest cl-print-tests-ellipsis-cons ()
126 "Ellipsis expansion works in conses." 34 "Ellipsis expansion works in conses."
127 (let ((print-length 4) 35 (let ((print-length 4)
@@ -216,23 +124,6 @@
216 (should (string-match expanded (with-output-to-string 124 (should (string-match expanded (with-output-to-string
217 (cl-print-expand-ellipsis value nil)))))) 125 (cl-print-expand-ellipsis value nil))))))
218 126
219(ert-deftest cl-print-circle ()
220 (let ((x '(#1=(a . #1#) #1#)))
221 (let ((print-circle nil))
222 (should (string-match "\\`((a . #[0-9]) (a . #[0-9]))\\'"
223 (cl-prin1-to-string x))))
224 (let ((print-circle t))
225 (should (equal "(#1=(a . #1#) #1#)" (cl-prin1-to-string x))))))
226
227(ert-deftest cl-print-circle-2 ()
228 ;; Bug#31146.
229 (let ((x '(0 . #1=(0 . #1#))))
230 (let ((print-circle nil))
231 (should (string-match "\\`(0 0 . #[0-9])\\'"
232 (cl-prin1-to-string x))))
233 (let ((print-circle t))
234 (should (equal "(0 . #1=(0 . #1#))" (cl-prin1-to-string x))))))
235
236(ert-deftest cl-print-tests-print-to-string-with-limit () 127(ert-deftest cl-print-tests-print-to-string-with-limit ()
237 (let* ((thing10 (make-list 10 'a)) 128 (let* ((thing10 (make-list 10 'a))
238 (thing100 (make-list 100 'a)) 129 (thing100 (make-list 100 'a))