1 ;;; lread-tests.el --- tests for lread.c -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2016-2018 Free Software Foundation, Inc.
5 ;; Author: Philipp Stephani <phst@google.com>
7 ;; This file is part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
24 ;; Unit tests for code in src/lread.c.
28 (ert-deftest lread-char-number
()
29 (should (equal (read "?\\N{U+A817}") #xA817
)))
31 (ert-deftest lread-char-name-1
()
32 (should (equal (read "?\\N{SYLOTI NAGRI LETTER \n DHO}")
34 (ert-deftest lread-char-name-2
()
35 (should (equal (read "?\\N{BED}") #x1F6CF
)))
36 (ert-deftest lread-char-name-3
()
37 (should (equal (read "?\\N{U+BED}") #xBED
)))
38 (ert-deftest lread-char-name-4
()
39 (should (equal (read "?\\N{VARIATION SELECTOR-1}") #xFE00
)))
40 (ert-deftest lread-char-name-5
()
41 (should (equal (read "?\\N{VARIATION SELECTOR-16}") #xFE0F
)))
42 (ert-deftest lread-char-name-6
()
43 (should (equal (read "?\\N{VARIATION SELECTOR-17}") #xE0100
)))
44 (ert-deftest lread-char-name-7
()
45 (should (equal (read "?\\N{VARIATION SELECTOR-256}") #xE01EF
)))
46 (ert-deftest lread-char-name-8
()
47 (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-F900}") #xF900
)))
48 (ert-deftest lread-char-name-9
()
49 (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-FAD9}") #xFAD9
)))
50 (ert-deftest lread-char-name-10
()
51 (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2F800}") #x2F800
)))
52 (ert-deftest lread-char-name-11
()
53 (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2FA1D}") #x2FA1D
)))
55 (ert-deftest lread-char-invalid-number
()
56 (should-error (read "?\\N{U+110000}") :type
'invalid-read-syntax
))
58 (ert-deftest lread-char-invalid-name-1
()
59 (should-error (read "?\\N{DOES NOT EXIST}")) :type
'invalid-read-syntax
)
60 (ert-deftest lread-char-invalid-name-2
()
61 (should-error (read "?\\N{VARIATION SELECTOR-0}")) :type
'invalid-read-syntax
)
62 (ert-deftest lread-char-invalid-name-3
()
63 (should-error (read "?\\N{VARIATION SELECTOR-257}"))
64 :type
'invalid-read-syntax
)
65 (ert-deftest lread-char-invalid-name-4
()
66 (should-error (read "?\\N{VARIATION SELECTOR--0}"))
67 :type
'invalid-read-syntax
)
68 (ert-deftest lread-char-invalid-name-5
()
69 (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-F8FF}"))
70 :type
'invalid-read-syntax
)
71 (ert-deftest lread-char-invalid-name-6
()
72 (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-FADA}"))
73 :type
'invalid-read-syntax
)
74 (ert-deftest lread-char-invalid-name-7
()
75 (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2F7FF}"))
76 :type
'invalid-read-syntax
)
77 (ert-deftest lread-char-invalid-name-8
()
78 (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2FA1E}"))
79 :type
'invalid-read-syntax
)
81 (ert-deftest lread-char-non-ascii-name
()
82 (should-error (read "?\\N{LATIN CAPITAL LETTER Ø}")
83 :type
'invalid-read-syntax
))
85 (ert-deftest lread-char-empty-name
()
86 (should-error (read "?\\N{}") :type
'invalid-read-syntax
))
88 (ert-deftest lread-char-surrogate-1
()
89 (should-error (read "?\\N{U+D800}") :type
'invalid-read-syntax
))
90 (ert-deftest lread-char-surrogate-2
()
91 (should-error (read "?\\N{U+D801}") :type
'invalid-read-syntax
))
92 (ert-deftest lread-char-surrogate-3
()
93 (should-error (read "?\\N{U+Dffe}") :type
'invalid-read-syntax
))
94 (ert-deftest lread-char-surrogate-4
()
95 (should-error (read "?\\N{U+DFFF}") :type
'invalid-read-syntax
))
97 (ert-deftest lread-string-char-number-1
()
98 (should (equal (read "\"a\\N{U+A817}b\"") "a\uA817b")))
99 (ert-deftest lread-string-char-number-2
()
100 (should-error (read "?\\N{0.5}") :type
'invalid-read-syntax
))
101 (ert-deftest lread-string-char-number-3
()
102 (should-error (read "?\\N{U+-0}") :type
'invalid-read-syntax
))
104 (ert-deftest lread-string-char-name
()
105 (should (equal (read "\"a\\N{SYLOTI NAGRI LETTER DHO}b\"") "a\uA817b")))
107 (ert-deftest lread-empty-int-literal
()
108 "Check that Bug#25120 is fixed."
109 (should-error (read "#b") :type
'invalid-read-syntax
)
110 (should-error (read "#o") :type
'invalid-read-syntax
)
111 (should-error (read "#x") :type
'invalid-read-syntax
)
112 (should-error (read "#24r") :type
'invalid-read-syntax
)
113 (should-error (read "#") :type
'invalid-read-syntax
))
115 (ert-deftest lread-record-1
()
116 (should (equal '(#s
(foo) #s
(foo))
117 (read "(#1=#s(foo) #1#)"))))
119 (defmacro lread-tests--with-temp-file
(file-name-var &rest body
)
121 (cl-check-type file-name-var symbol
)
122 `(let ((,file-name-var
(make-temp-file "emacs")))
125 (delete-file ,file-name-var
))))
127 (defun lread-tests--last-message ()
128 (with-current-buffer "*Messages*"
130 (goto-char (point-max))
131 (skip-chars-backward "\n")
132 (buffer-substring (line-beginning-position) (point)))))
134 (ert-deftest lread-tests--unescaped-char-literals
()
135 "Check that loading warns about unescaped character
136 literals (Bug#20852)."
137 (lread-tests--with-temp-file file-name
138 (write-region "?) ?( ?; ?\" ?[ ?]" nil file-name
)
139 (should (equal (load file-name nil
:nomessage
:nosuffix
) t
))
140 (should (equal (lread-tests--last-message)
141 (concat (format-message "Loading `%s': " file-name
)
142 "unescaped character literals "
143 "`?\"', `?(', `?)', `?;', `?[', `?]' detected!")))))
145 (ert-deftest lread-test-bug26837
()
146 "Test for https://debbugs.gnu.org/26837 ."
147 (let ((load-path (cons
148 (file-name-as-directory
149 (expand-file-name "data" (getenv "EMACS_TEST_DIRECTORY")))
151 (load "somelib" nil t
)
152 (should (string-suffix-p "/somelib.el" (caar load-history
)))
153 (load "somelib2" nil t
)
154 (should (string-suffix-p "/somelib2.el" (caar load-history
)))
155 (load "somelib" nil t
)
156 (should (string-suffix-p "/somelib.el" (caar load-history
)))))
158 (ert-deftest lread-tests--old-style-backquotes
()
159 "Check that loading warns about old-style backquotes."
160 (lread-tests--with-temp-file file-name
161 (write-region "(` (a b))" nil file-name
)
162 (should (equal (load file-name nil
:nomessage
:nosuffix
) t
))
163 (should (equal (lread-tests--last-message)
164 (concat (format-message "Loading `%s': " file-name
)
165 "old-style backquotes detected!")))))
167 (ert-deftest lread-lread--substitute-object-in-subtree
()
168 (let ((x (cons 0 1)))
170 (lread--substitute-object-in-subtree x
1 t
)
171 (should (eq x
(cdr x
)))))
173 ;;; lread-tests.el ends here