Honor print-charset-text-property value of nil (Bug#31376)
[emacs.git] / test / src / print-tests.el
blobc96cb5d2b6971e0d15069e1abecf2dffb134cce0
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/>.
20 ;;; Code:
22 (require 'ert)
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"))
28 "\"\\x00a2\\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."
35 (integerp
36 (string-match
37 "charset"
38 (prin1-to-string
39 (propertize (string ch)
40 'charset
41 (if odd-charset
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
68 (princ 'abc)
69 (should (terpri nil t)))
70 "abc\n"))
71 (should (string= (with-output-to-string
72 (should-not (terpri nil t))
73 (princ 'xyz))
74 "xyz"))
75 (message nil)
76 (if noninteractive
77 (progn (should (terpri nil t))
78 (should-not (terpri nil t))
79 (princ 'abc)
80 (should (terpri nil t))
81 (should-not (terpri nil t)))
82 (should (string= (progn (should-not (terpri nil t))
83 (princ 'abc)
84 (should (terpri nil t))
85 (current-message))
86 "abc\n")))
87 (let ((standard-output
88 (with-current-buffer (get-buffer-create "*terpri-test*")
89 (insert "--------")
90 (point-max-marker))))
91 (should (terpri nil t))
92 (should-not (terpri nil t))
93 (should (string= (with-current-buffer (marker-buffer standard-output)
94 (buffer-string))
95 "--------\n"))))
97 (ert-deftest print-read-roundtrip ()
98 (let ((sym '\’bar))
99 (should (eq (read (prin1-to-string sym)) sym))))
101 (provide 'print-tests)
102 ;;; print-tests.el ends here