1 ;;; print-tests.el --- tests for src/print.c -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2014-2018 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
24 (ert-deftest print-hex-backslash
()
25 (should (string= (let ((print-escape-multibyte t
)
26 (print-escape-newlines t
))
27 (prin1-to-string "\u00A2\ff"))
30 (defun print-tests--prints-with-charset-p (ch odd-charset
)
31 "Return t if `prin1-to-string' prints CH with the `charset' property.
32 CH is propertized with a `charset' value according to
33 ODD-CHARSET: if nil, then use the one returned by `char-charset',
34 otherwise, use a different charset."
39 (propertize (string ch
)
42 (cl-find (char-charset ch
) charset-list
:test-not
#'eq
)
43 (char-charset ch
)))))))
45 (ert-deftest print-charset-text-property-nil
()
46 (let ((print-charset-text-property nil
))
47 (should-not (print-tests--prints-with-charset-p ?
\xf6 t
)) ; Bug#31376.
48 (should-not (print-tests--prints-with-charset-p ?a t
))
49 (should-not (print-tests--prints-with-charset-p ?
\xf6 nil
))
50 (should-not (print-tests--prints-with-charset-p ?a nil
))))
52 (ert-deftest print-charset-text-property-default
()
53 (let ((print-charset-text-property 'default
))
54 (should (print-tests--prints-with-charset-p ?
\xf6 t
))
55 (should-not (print-tests--prints-with-charset-p ?a t
))
56 (should-not (print-tests--prints-with-charset-p ?
\xf6 nil
))
57 (should-not (print-tests--prints-with-charset-p ?a nil
))))
59 (ert-deftest print-charset-text-property-t
()
60 (let ((print-charset-text-property t
))
61 (should (print-tests--prints-with-charset-p ?
\xf6 t
))
62 (should (print-tests--prints-with-charset-p ?a t
))
63 (should (print-tests--prints-with-charset-p ?
\xf6 nil
))
64 (should (print-tests--prints-with-charset-p ?a nil
))))
66 (ert-deftest terpri
()
67 (should (string= (with-output-to-string
69 (should (terpri nil t
)))
71 (should (string= (with-output-to-string
72 (should-not (terpri nil t
))
77 (progn (should (terpri nil t
))
78 (should-not (terpri nil t
))
80 (should (terpri nil t
))
81 (should-not (terpri nil t
)))
82 (should (string= (progn (should-not (terpri nil t
))
84 (should (terpri nil t
))
87 (let ((standard-output
88 (with-current-buffer (get-buffer-create "*terpri-test*")
91 (should (terpri nil t
))
92 (should-not (terpri nil t
))
93 (should (string= (with-current-buffer (marker-buffer standard-output
)
97 (ert-deftest print-read-roundtrip
()
99 (should (eq (read (prin1-to-string sym
)) sym
))))
101 (provide 'print-tests
)
102 ;;; print-tests.el ends here