428
|
1 ;; Copyright (C) 1999 Free Software Foundation, Inc.
|
|
2
|
|
3 ;; Author: Hrvoje Niksic <hniksic@xemacs.org>
|
440
|
4 ;; Maintainers: Hrvoje Niksic <hniksic@xemacs.org>,
|
|
5 ;; Martin Buchholz <martin@xemacs.org>
|
428
|
6 ;; Created: 1999
|
|
7 ;; Keywords: tests
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: Not in FSF.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; Test some Mule functionality (most of these remain to be written) .
|
|
31 ;; See test-harness.el for instructions on how to run these tests.
|
|
32
|
434
|
33 ;; This file will be (read)ed by a non-mule XEmacs, so don't use
|
|
34 ;; literal non-Latin1 characters. Use (make-char) instead.
|
|
35
|
3948
|
36 (require 'bytecomp)
|
|
37
|
428
|
38 ;;-----------------------------------------------------------------
|
|
39 ;; Test whether all legal chars may be safely inserted to a buffer.
|
|
40 ;;-----------------------------------------------------------------
|
|
41
|
|
42 (defun test-chars (&optional for-test-harness)
|
|
43 "Insert all characters in a buffer, to see if XEmacs will crash.
|
|
44 This is done by creating a string with all the legal characters
|
|
45 in [0, 2^19) range, inserting it into the buffer, and checking
|
|
46 that the buffer's contents are equivalent to the string.
|
|
47
|
|
48 If FOR-TEST-HARNESS is specified, a temporary buffer is used, and
|
|
49 the Assert macro checks for correctness."
|
|
50 (let ((max (expt 2 (if (featurep 'mule) 19 8)))
|
|
51 (list nil)
|
|
52 (i 0))
|
|
53 (while (< i max)
|
|
54 (and (not for-test-harness)
|
|
55 (zerop (% i 1000))
|
|
56 (message "%d" i))
|
|
57 (and (int-char i)
|
|
58 ;; Don't aset to a string directly because random string
|
|
59 ;; access is O(n) under Mule.
|
|
60 (setq list (cons (int-char i) list)))
|
|
61 (setq i (1+ i)))
|
|
62 (let ((string (apply #'string (nreverse list))))
|
|
63 (if for-test-harness
|
|
64 ;; For use with test-harness, use Assert and a temporary
|
|
65 ;; buffer.
|
|
66 (with-temp-buffer
|
|
67 (insert string)
|
|
68 (Assert (equal (buffer-string) string)))
|
|
69 ;; For use without test harness: use a normal buffer, so that
|
|
70 ;; you can also test whether redisplay works.
|
|
71 (switch-to-buffer (get-buffer-create "test"))
|
|
72 (erase-buffer)
|
|
73 (buffer-disable-undo)
|
|
74 (insert string)
|
|
75 (assert (equal (buffer-string) string))))))
|
|
76
|
|
77 ;; It would be really *really* nice if test-harness allowed a way to
|
|
78 ;; run a test in byte-compiled mode only. It's tedious to have
|
|
79 ;; time-consuming tests like this one run twice, once interpreted and
|
|
80 ;; once compiled, for no good reason.
|
|
81 (test-chars t)
|
434
|
82
|
3439
|
83 (defun unicode-code-point-to-utf-8-string (code-point)
|
|
84 "Convert a Unicode code point to the equivalent UTF-8 string.
|
|
85 This is a naive implementation in Lisp. "
|
|
86 (check-argument-type 'natnump code-point)
|
|
87 (check-argument-range code-point 0 #x1fffff)
|
|
88 (if (< code-point #x80)
|
|
89 (format "%c" code-point)
|
|
90 (if (< code-point #x800)
|
|
91 (format "%c%c"
|
|
92 ;; ochars[0] = 0xC0 | (input & ~(0xFFFFF83F)) >> 6;
|
|
93 (logior #xc0 (lsh (logand code-point #x7c0) -6))
|
|
94 ;; ochars[1] = 0x80 | input & ~(0xFFFFFFC0);
|
|
95 (logior #x80 (logand code-point #x3f)))
|
|
96 (if (< code-point #x00010000)
|
|
97 (format "%c%c%c"
|
|
98 ;; ochars[0] = 0xE0 | (input >> 12) & ~(0xFFFFFFF0);
|
|
99 (logior #xe0 (logand (lsh code-point -12) #x0f))
|
|
100 ;; ochars[1] = 0x80 | (input >> 6) & ~(0xFFFFFFC0);
|
|
101 (logior #x80 (logand (lsh code-point -6) #x3f))
|
|
102 ;; ochars[2] = 0x80 | input & ~(0xFFFFFFC0);
|
|
103 (logior #x80 (logand code-point #x3f)))
|
|
104 (if (< code-point #x200000)
|
|
105 (format "%c%c%c%c"
|
|
106 ;; ochars[0] = 0xF0 | (input >> 18) & ~(0xFFFFFFF8)
|
|
107 (logior #xF0 (logand (lsh code-point -18) #x7))
|
|
108 ;; ochars[1] = 0x80 | (input >> 12) & ~(0xFFFFFFC0);
|
|
109 (logior #x80 (logand (lsh code-point -12) #x3f))
|
|
110 ;; ochars[2] = 0x80 | (input >> 6) & ~(0xFFFFFFC0);
|
|
111 (logior #x80 (logand (lsh code-point -6) #x3f))
|
|
112 ;; ochars[3] = 0x80 | input & ~(0xFFFFFFC0);
|
|
113 (logior #x80 (logand code-point #x3f))))))))
|
|
114
|
434
|
115 ;;-----------------------------------------------------------------
|
|
116 ;; Test string modification functions that modify the length of a char.
|
|
117 ;;-----------------------------------------------------------------
|
|
118
|
|
119 (when (featurep 'mule)
|
442
|
120 ;;---------------------------------------------------------------
|
434
|
121 ;; Test fillarray
|
442
|
122 ;;---------------------------------------------------------------
|
434
|
123 (macrolet
|
|
124 ((fillarray-test
|
|
125 (charset1 charset2)
|
|
126 (let ((char1 (make-char charset1 69))
|
|
127 (char2 (make-char charset2 69)))
|
|
128 `(let ((string (make-string 1000 ,char1)))
|
|
129 (fillarray string ,char2)
|
|
130 (Assert (eq (aref string 0) ,char2))
|
|
131 (Assert (eq (aref string (1- (length string))) ,char2))
|
|
132 (Assert (eq (length string) 1000))))))
|
|
133 (fillarray-test ascii latin-iso8859-1)
|
|
134 (fillarray-test ascii latin-iso8859-2)
|
|
135 (fillarray-test latin-iso8859-1 ascii)
|
|
136 (fillarray-test latin-iso8859-2 ascii))
|
|
137
|
|
138 ;; Test aset
|
|
139 (let ((string (string (make-char 'ascii 69) (make-char 'latin-iso8859-2 69))))
|
|
140 (aset string 0 (make-char 'latin-iso8859-2 42))
|
|
141 (Assert (eq (aref string 1) (make-char 'latin-iso8859-2 69))))
|
|
142
|
442
|
143 ;;---------------------------------------------------------------
|
440
|
144 ;; Test coding system functions
|
442
|
145 ;;---------------------------------------------------------------
|
440
|
146
|
|
147 ;; Create alias for coding system without subsidiaries
|
|
148 (Assert (coding-system-p (find-coding-system 'binary)))
|
|
149 (Assert (coding-system-canonical-name-p 'binary))
|
|
150 (Assert (not (coding-system-alias-p 'binary)))
|
|
151 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
|
|
152 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
153 (Check-Error-Message
|
|
154 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
155 (define-coding-system-alias 'binary 'iso8859-2))
|
|
156 (Check-Error-Message
|
|
157 error "Symbol is not a coding system alias"
|
|
158 (coding-system-aliasee 'binary))
|
|
159
|
|
160 (define-coding-system-alias 'mule-tests-alias 'binary)
|
|
161 (Assert (coding-system-alias-p 'mule-tests-alias))
|
|
162 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
163 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
|
|
164 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
|
|
165 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
|
|
166 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
|
|
167 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
|
|
168
|
|
169 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'binary))
|
|
170 (Assert (coding-system-alias-p 'mule-tests-alias))
|
|
171 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
172 (Assert (eq (get-coding-system 'binary) (get-coding-system 'mule-tests-alias)))
|
|
173 (Assert (eq 'binary (coding-system-aliasee 'mule-tests-alias)))
|
|
174 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
|
|
175 (Assert (not (coding-system-alias-p 'mule-tests-alias-dos)))
|
|
176 (Assert (not (coding-system-alias-p 'mule-tests-alias-mac)))
|
|
177
|
|
178 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
|
|
179 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
|
|
180 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
|
|
181 (Assert (eq (get-coding-system 'binary) (get-coding-system 'nested-mule-tests-alias)))
|
|
182 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
|
|
183 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
|
|
184 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-unix)))
|
|
185 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
|
|
186 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-mac)))
|
|
187
|
|
188 (Check-Error-Message
|
|
189 error "Attempt to create a coding system alias loop"
|
|
190 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
191 (Check-Error-Message
|
|
192 error "No such coding system"
|
|
193 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
194 (Check-Error-Message
|
|
195 error "Attempt to create a coding system alias loop"
|
|
196 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
197
|
|
198 (define-coding-system-alias 'nested-mule-tests-alias nil)
|
|
199 (define-coding-system-alias 'mule-tests-alias nil)
|
|
200 (Assert (coding-system-p (find-coding-system 'binary)))
|
|
201 (Assert (coding-system-canonical-name-p 'binary))
|
|
202 (Assert (not (coding-system-alias-p 'binary)))
|
|
203 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
|
|
204 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
205 (Check-Error-Message
|
|
206 error "Symbol is the canonical name of a coding system and cannot be redefined"
|
|
207 (define-coding-system-alias 'binary 'iso8859-2))
|
|
208 (Check-Error-Message
|
|
209 error "Symbol is not a coding system alias"
|
|
210 (coding-system-aliasee 'binary))
|
|
211
|
|
212 (define-coding-system-alias 'nested-mule-tests-alias nil)
|
|
213 (define-coding-system-alias 'mule-tests-alias nil)
|
|
214
|
|
215 ;; Create alias for coding system with subsidiaries
|
|
216 (define-coding-system-alias 'mule-tests-alias 'iso-8859-7)
|
|
217 (Assert (coding-system-alias-p 'mule-tests-alias))
|
|
218 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
219 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
|
|
220 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
|
|
221 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
|
|
222 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
|
|
223 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
|
|
224
|
|
225 (define-coding-system-alias 'mule-tests-alias (get-coding-system 'iso-8859-7))
|
|
226 (Assert (coding-system-alias-p 'mule-tests-alias))
|
|
227 (Assert (not (coding-system-canonical-name-p 'mule-tests-alias)))
|
|
228 (Assert (eq (get-coding-system 'iso-8859-7) (get-coding-system 'mule-tests-alias)))
|
|
229 (Assert (eq 'iso-8859-7 (coding-system-aliasee 'mule-tests-alias)))
|
|
230 (Assert (coding-system-alias-p 'mule-tests-alias-unix))
|
|
231 (Assert (coding-system-alias-p 'mule-tests-alias-dos))
|
|
232 (Assert (coding-system-alias-p 'mule-tests-alias-mac))
|
|
233 (Assert (eq (find-coding-system 'mule-tests-alias-mac)
|
|
234 (find-coding-system 'iso-8859-7-mac)))
|
|
235
|
|
236 (define-coding-system-alias 'nested-mule-tests-alias 'mule-tests-alias)
|
|
237 (Assert (coding-system-alias-p 'nested-mule-tests-alias))
|
|
238 (Assert (not (coding-system-canonical-name-p 'nested-mule-tests-alias)))
|
|
239 (Assert (eq (get-coding-system 'iso-8859-7)
|
|
240 (get-coding-system 'nested-mule-tests-alias)))
|
|
241 (Assert (eq (coding-system-aliasee 'nested-mule-tests-alias) 'mule-tests-alias))
|
|
242 (Assert (eq 'mule-tests-alias (coding-system-aliasee 'nested-mule-tests-alias)))
|
|
243 (Assert (coding-system-alias-p 'nested-mule-tests-alias-unix))
|
|
244 (Assert (coding-system-alias-p 'nested-mule-tests-alias-dos))
|
|
245 (Assert (coding-system-alias-p 'nested-mule-tests-alias-mac))
|
|
246 (Assert (eq (find-coding-system 'nested-mule-tests-alias-unix)
|
|
247 (find-coding-system 'iso-8859-7-unix)))
|
|
248
|
|
249 (Check-Error-Message
|
|
250 error "Attempt to create a coding system alias loop"
|
|
251 (define-coding-system-alias 'mule-tests-alias 'nested-mule-tests-alias))
|
|
252 (Check-Error-Message
|
|
253 error "No such coding system"
|
|
254 (define-coding-system-alias 'no-such-coding-system 'no-such-coding-system))
|
|
255 (Check-Error-Message
|
|
256 error "Attempt to create a coding system alias loop"
|
|
257 (define-coding-system-alias 'mule-tests-alias 'mule-tests-alias))
|
|
258
|
|
259 ;; Test dangling alias deletion
|
|
260 (define-coding-system-alias 'mule-tests-alias nil)
|
|
261 (Assert (not (coding-system-alias-p 'mule-tests-alias)))
|
|
262 (Assert (not (coding-system-alias-p 'mule-tests-alias-unix)))
|
|
263 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias)))
|
|
264 (Assert (not (coding-system-alias-p 'nested-mule-tests-alias-dos)))
|
|
265
|
442
|
266 ;;---------------------------------------------------------------
|
438
|
267 ;; Test strings waxing and waning across the 8k BIG_STRING limit (see alloc.c)
|
442
|
268 ;;---------------------------------------------------------------
|
438
|
269 (defun charset-char-string (charset)
|
2026
|
270 (let (lo hi string n (gc-cons-threshold most-positive-fixnum))
|
438
|
271 (if (= (charset-chars charset) 94)
|
|
272 (setq lo 33 hi 126)
|
|
273 (setq lo 32 hi 127))
|
|
274 (if (= (charset-dimension charset) 1)
|
|
275 (progn
|
|
276 (setq string (make-string (1+ (- hi lo)) ??))
|
|
277 (setq n 0)
|
|
278 (loop for j from lo to hi do
|
|
279 (progn
|
|
280 (aset string n (make-char charset j))
|
|
281 (incf n)))
|
2026
|
282 (garbage-collect)
|
438
|
283 string)
|
|
284 (progn
|
|
285 (setq string (make-string (* (1+ (- hi lo)) (1+ (- hi lo))) ??))
|
|
286 (setq n 0)
|
|
287 (loop for j from lo to hi do
|
|
288 (loop for k from lo to hi do
|
|
289 (progn
|
|
290 (aset string n (make-char charset j k))
|
|
291 (incf n))))
|
2026
|
292 (garbage-collect)
|
438
|
293 string))))
|
|
294
|
|
295 ;; The following two used to crash xemacs!
|
|
296 (Assert (charset-char-string 'japanese-jisx0208))
|
|
297 (aset (make-string 9003 ??) 1 (make-char 'latin-iso8859-1 77))
|
|
298
|
|
299 (let ((greek-string (charset-char-string 'greek-iso8859-7))
|
|
300 (string (make-string (* 96 60) ??)))
|
|
301 (loop for j from 0 below (length string) do
|
|
302 (aset string j (aref greek-string (mod j 96))))
|
|
303 (loop for k in '(0 1 58 59) do
|
|
304 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
|
|
305
|
|
306 (let ((greek-string (charset-char-string 'greek-iso8859-7))
|
|
307 (string (make-string (* 96 60) ??)))
|
|
308 (loop for j from (1- (length string)) downto 0 do
|
|
309 (aset string j (aref greek-string (mod j 96))))
|
|
310 (loop for k in '(0 1 58 59) do
|
|
311 (Assert (equal (substring string (* 96 k) (* 96 (1+ k))) greek-string))))
|
|
312
|
|
313 (let ((ascii-string (charset-char-string 'ascii))
|
|
314 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
|
|
315 (loop for j from 0 below (length string) do
|
|
316 (aset string j (aref ascii-string (mod j 94))))
|
|
317 (loop for k in '(0 1 58 59) do
|
|
318 (Assert (equal (substring string (* 94 k) (+ 94 (* 94 k))) ascii-string))))
|
|
319
|
|
320 (let ((ascii-string (charset-char-string 'ascii))
|
|
321 (string (make-string (* 94 60) (make-char 'greek-iso8859-7 57))))
|
|
322 (loop for j from (1- (length string)) downto 0 do
|
|
323 (aset string j (aref ascii-string (mod j 94))))
|
|
324 (loop for k in '(0 1 58 59) do
|
|
325 (Assert (equal (substring string (* 94 k) (* 94 (1+ k))) ascii-string))))
|
|
326
|
442
|
327 ;;---------------------------------------------------------------
|
|
328 ;; Test file-system character conversion (and, en passant, file ops)
|
|
329 ;;---------------------------------------------------------------
|
3970
|
330 (let* ((dstroke (make-char 'latin-iso8859-2 80))
|
|
331 (latin2-string (make-string 4 dstroke))
|
597
|
332 (prefix (concat (file-name-as-directory
|
|
333 (file-truename (temp-directory)))
|
|
334 latin2-string))
|
2026
|
335 (file-name-coding-system
|
|
336 ;; 'iso-8859-X doesn't work on darwin (as of "Panther" 10.3), it
|
|
337 ;; seems to know that file-name-coding-system is definitely utf-8
|
|
338 (if (string-match "darwin" system-configuration)
|
|
339 'utf-8
|
|
340 'iso-8859-2))
|
3970
|
341 ;; make-temp-name does stat(), which on OS X requires that you
|
|
342 ;; normalise, where open() will normalise for you. Previously we
|
|
343 ;; used scaron as the Latin-2 character, and make-temp-name errored
|
|
344 ;; on OS X. LATIN CAPITAL LETTER D WITH STROKE does decompose.
|
|
345 (name1 (make-temp-name prefix))
|
|
346 (name2 (make-temp-name prefix)))
|
|
347 ;; This is how you suppress output from `message', called by `write-region'
|
3472
|
348 (Assert (not (equal name1 name2)))
|
|
349 (Assert (not (file-exists-p name1)))
|
|
350 (Silence-Message
|
|
351 (write-region (point-min) (point-max) name1))
|
|
352 (Assert (file-exists-p name1))
|
|
353 (when (fboundp 'make-symbolic-link)
|
|
354 (make-symbolic-link name1 name2)
|
|
355 (Assert (file-exists-p name2))
|
|
356 (Assert (equal (file-truename name2) name1))
|
|
357 (Assert (equal (file-truename name1) name1)))
|
3970
|
358 (ignore-file-errors (delete-file name1) (delete-file name2)))
|
442
|
359
|
|
360 ;; Add many more file operation tests here...
|
|
361
|
|
362 ;;---------------------------------------------------------------
|
|
363 ;; Test Unicode-related functions
|
|
364 ;;---------------------------------------------------------------
|
|
365 (let* ((scaron (make-char 'latin-iso8859-2 57)))
|
875
|
366 ;; Used to try #x0000, but you can't change ASCII or Latin-1
|
|
367 (loop for code in '(#x0100 #x2222 #x4444 #xffff) do
|
442
|
368 (progn
|
800
|
369 (set-unicode-conversion scaron code)
|
|
370 (Assert (eq code (char-to-unicode scaron)))
|
|
371 (Assert (eq scaron (unicode-to-char code '(latin-iso8859-2))))))
|
442
|
372
|
800
|
373 (Check-Error wrong-type-argument (set-unicode-conversion scaron -10000)))
|
1195
|
374
|
3439
|
375 (dolist (utf-8-char
|
|
376 '("\xc6\x92" ;; U+0192 LATIN SMALL LETTER F WITH HOOK
|
|
377 "\xe2\x81\x8a" ;; U+204A TIRONIAN SIGN ET
|
|
378 "\xe2\x82\xae" ;; U+20AE TUGRIK SIGN
|
|
379 "\xf0\x9d\x92\xbd" ;; U+1D4BD MATHEMATICAL SCRIPT SMALL H
|
|
380 "\xf0\x9d\x96\x93" ;; U+1D593 MATHEMATICAL BOLD FRAKTUR SMALL N
|
|
381 "\xf0\xaf\xa8\x88" ;; U+2FA08 CJK COMPATIBILITY FOR U+4BCE
|
|
382 "\xf4\x8f\xbf\xbd")) ;; U+10FFFD <Plane 16 Private Use, Last>
|
|
383 (let* ((xemacs-character (car (append
|
|
384 (decode-coding-string utf-8-char 'utf-8)
|
|
385 nil)))
|
|
386 (xemacs-charset (car (split-char xemacs-character))))
|
|
387
|
|
388 ;; Trivial test of the UTF-8 support of the escape-quoted character set.
|
|
389 (Assert (equal (decode-coding-string utf-8-char 'utf-8)
|
|
390 (decode-coding-string (concat "\033%G" utf-8-char)
|
|
391 'escape-quoted)))
|
|
392
|
|
393 ;; Check that the reverse mapping holds.
|
|
394 (Assert (equal (unicode-code-point-to-utf-8-string
|
|
395 (encode-char xemacs-character 'ucs))
|
|
396 utf-8-char))
|
|
397
|
|
398 ;; Check that, if this character has been JIT-allocated, it is encoded
|
|
399 ;; in escape-quoted using the corresponding UTF-8 escape.
|
|
400 (when (charset-property xemacs-charset 'encode-as-utf-8)
|
|
401 (Assert (equal (concat "\033%G" utf-8-char)
|
|
402 (encode-coding-string xemacs-character 'escape-quoted)))
|
|
403 (Assert (equal (concat "\033%G" utf-8-char)
|
|
404 (encode-coding-string xemacs-character 'ctext))))))
|
|
405
|
3952
|
406 (loop
|
|
407 for (code-point encoded)
|
|
408 in '((#x10000 "\xd8\x00\xdc\x00")
|
|
409 (#x10FFFD "\xdb\xff\xdf\xfd"))
|
|
410 do (Assert (equal (encode-coding-string
|
|
411 (decode-char 'ucs code-point) 'utf-16)
|
|
412 encoded)))
|
|
413
|
1195
|
414 ;;---------------------------------------------------------------
|
3690
|
415 ;; Regression test for a couple of CCL-related bugs.
|
|
416 ;;---------------------------------------------------------------
|
|
417
|
|
418 (let ((ccl-vector [0 0 0 0 0 0 0 0 0]))
|
|
419 (define-ccl-program ccl-write-two-control-1-chars
|
|
420 `(1
|
|
421 ((r0 = ,(charset-id 'control-1))
|
|
422 (r1 = 0)
|
|
423 (write-multibyte-character r0 r1)
|
|
424 (r1 = 31)
|
|
425 (write-multibyte-character r0 r1)))
|
|
426 "CCL program that writes two control-1 multibyte characters.")
|
|
427
|
|
428 (Assert (equal
|
|
429 (ccl-execute-on-string 'ccl-write-two-control-1-chars
|
|
430 ccl-vector "")
|
|
431 (format "%c%c" (make-char 'control-1 0)
|
|
432 (make-char 'control-1 31))))
|
|
433
|
|
434 (define-ccl-program ccl-unicode-two-control-1-chars
|
|
435 `(1
|
|
436 ((r0 = ,(charset-id 'control-1))
|
|
437 (r1 = 31)
|
|
438 (mule-to-unicode r0 r1)
|
|
439 (r4 = r0)
|
|
440 (r3 = ,(charset-id 'control-1))
|
|
441 (r2 = 0)
|
|
442 (mule-to-unicode r3 r2)))
|
|
443 "CCL program that writes two control-1 UCS code points in r3 and r4")
|
|
444
|
|
445 ;; Re-initialise the vector, mainly to clear the instruction counter,
|
|
446 ;; which is its last element.
|
|
447 (setq ccl-vector [0 0 0 0 0 0 0 0 0])
|
|
448
|
|
449 (ccl-execute-on-string 'ccl-unicode-two-control-1-chars ccl-vector "")
|
|
450
|
|
451 (Assert (and (eq (aref ccl-vector 3)
|
|
452 (encode-char (make-char 'control-1 0) 'ucs))
|
|
453 (eq (aref ccl-vector 4)
|
|
454 (encode-char (make-char 'control-1 31) 'ucs)))))
|
|
455
|
|
456 ;;---------------------------------------------------------------
|
1195
|
457 ;; Test charset-in-* functions
|
|
458 ;;---------------------------------------------------------------
|
|
459 (with-temp-buffer
|
|
460 (insert-file-contents (locate-data-file "HELLO"))
|
3927
|
461 (Assert (equal
|
|
462 ;; The sort is to make the algorithm of charsets-in-region
|
|
463 ;; irrelevant.
|
|
464 (sort (charsets-in-region (point-min) (point-max))
|
|
465 'string<)
|
|
466 '(arabic-1-column arabic-2-column ascii chinese-big5-1
|
|
467 chinese-gb2312 cyrillic-iso8859-5 ethiopic greek-iso8859-7
|
|
468 hebrew-iso8859-8 japanese-jisx0208 japanese-jisx0212
|
|
469 katakana-jisx0201 korean-ksc5601 latin-iso8859-1
|
|
470 latin-iso8859-2 thai-xtis vietnamese-viscii-lower)))
|
|
471 (Assert (equal
|
|
472 (sort (charsets-in-string (buffer-substring (point-min)
|
1316
|
473 (point-max)))
|
3927
|
474 'string<)
|
|
475 '(arabic-1-column arabic-2-column ascii chinese-big5-1
|
|
476 chinese-gb2312 cyrillic-iso8859-5 ethiopic greek-iso8859-7
|
|
477 hebrew-iso8859-8 japanese-jisx0208 japanese-jisx0212
|
|
478 katakana-jisx0201 korean-ksc5601 latin-iso8859-1
|
|
479 latin-iso8859-2 thai-xtis vietnamese-viscii-lower))))
|
3948
|
480
|
3970
|
481 ;; Language environments.
|
|
482 (dolist (language (mapcar 'car language-info-alist))
|
|
483 (set-language-environment language)
|
|
484 (Assert (equal language current-language-environment))
|
|
485 (set-input-method (get-language-info language 'input-method))
|
|
486 (Assert (equal (get-language-info language 'input-method)
|
|
487 current-input-method))
|
|
488 (dolist (charset (get-language-info language 'charset))
|
|
489 (Assert (charsetp (find-charset charset))))
|
|
490 (dolist (coding-system (get-language-info language 'coding-system))
|
|
491 (Assert (coding-system-p (find-coding-system coding-system))))
|
|
492 (dolist (coding-system (get-language-info language 'coding-system))
|
|
493 (Assert (coding-system-p (find-coding-system coding-system)))))
|
|
494
|
3948
|
495 (with-temp-buffer
|
|
496 (flet
|
|
497 ((Assert-elc-is-escape-quoted ()
|
|
498 "Assert the current buffer has an escape-quoted cookie if compiled."
|
|
499 (save-excursion
|
|
500 (let ((byte-compile-result (byte-compile-from-buffer
|
|
501 (current-buffer) nil nil))
|
|
502 (temporary-file-name (make-temp-name
|
|
503 (expand-file-name "zjPQ2Pk"
|
|
504 (temp-directory)))))
|
|
505 (byte-compile-insert-header
|
|
506 temporary-file-name
|
|
507 (current-buffer)
|
|
508 byte-compile-result)
|
|
509 (Assert (string-match "^;;;###coding system: escape-quoted"
|
|
510 (buffer-substring nil nil
|
|
511 byte-compile-result))))))
|
|
512 (Assert-elc-has-no-specified-encoding ()
|
|
513 "Assert the current buffer has no coding cookie if compiled."
|
|
514 (save-excursion
|
|
515 (let ((byte-compile-result (byte-compile-from-buffer
|
|
516 (current-buffer) nil nil))
|
|
517 (temporary-file-name (make-temp-name
|
|
518 (expand-file-name "zjPQ2Pk"
|
|
519 (temp-directory)))))
|
|
520 (byte-compile-insert-header
|
|
521 temporary-file-name
|
|
522 (current-buffer)
|
|
523 byte-compile-result)
|
|
524 (Assert (not (string-match
|
|
525 ";;;###coding system:"
|
|
526 (buffer-substring nil nil byte-compile-result))))))))
|
|
527 (insert
|
|
528 ;; Create a buffer creating the Unicode escapes.
|
|
529 #r" (defvar testing-mule-compilation-handling
|
|
530 (string ?\u371E ;; kDefinition beautiful; pretty, used
|
|
531 ;; in girl's name
|
|
532 ?\U0002A6A9 ;; kDefinition (Cant.) sound of shouting
|
|
533 ?\U0002A65B ;; kDefinition (Cant.) decayed teeth;
|
|
534 ;; tongue-tied
|
|
535 ?\U00010400 ;; DESERET CAPITAL LETTER LONG I
|
|
536 ?\u3263)) ;; CIRCLED HANGUL RIEUL ")
|
|
537
|
|
538 (Assert-elc-is-escape-quoted)
|
|
539 (delete-region (point-min) (point-max))
|
|
540
|
|
541 (insert
|
|
542 ;; This time, the buffer will contain the actual characters, because of
|
|
543 ;; u flag to the #r.
|
|
544 #ru" (defvar testing-mule-compilation-handling
|
|
545 (string ?\u371E ;; kDefinition beautiful; pretty, used
|
|
546 ;; in girl's name
|
|
547 ?\U0002A6A9 ;; kDefinition (Cant.) sound of shouting
|
|
548 ?\U0002A65B ;; kDefinition (Cant.) decayed teeth;
|
|
549 ;; tongue-tied
|
|
550 ?\U00010400 ;; DESERET CAPITAL LETTER LONG I
|
|
551 ?\u3263)) ;; CIRCLED HANGUL RIEUL ")
|
|
552
|
|
553 (Assert-elc-is-escape-quoted)
|
|
554 (delete-region (point-min) (point-max))
|
|
555
|
|
556 (insert
|
|
557 ;; Just a single four character escape.
|
|
558 #r" (defvar testing-mule-compilation-handling
|
|
559 (string ?\u371E)) ;; kDefinition beautiful; pretty, used")
|
|
560
|
|
561 (Assert-elc-is-escape-quoted)
|
|
562 (delete-region (point-min) (point-max))
|
|
563
|
|
564 (insert
|
|
565 ;; Just a single eight character escape.
|
|
566 #r" (defvar testing-mule-compilation-handling
|
|
567 (string ?\U0002A65B)) ;; kDefinition (Cant.) decayed teeth;")
|
|
568
|
|
569 (Assert-elc-is-escape-quoted)
|
|
570 (delete-region (point-min) (point-max))
|
|
571
|
|
572 (insert
|
|
573 ;; A single latin-1 hex digit escape
|
|
574 #r" (defvar testing-mule-compilation-handling
|
|
575 (string ?\xab)) ;; LEFT-POINTING DOUBLE ANGLE QUOTATION MARK")
|
|
576
|
|
577 (Assert-elc-has-no-specified-encoding)
|
|
578 (delete-region (point-min) (point-max))
|
|
579
|
|
580 (insert
|
|
581 ;; A single latin-1 character
|
|
582 #ru" (defvar testing-mule-compilation-handling
|
|
583 (string ?\u00AB)) ;; LEFT-POINTING DOUBLE ANGLE QUOTATION MARK")
|
|
584
|
|
585 (Assert-elc-has-no-specified-encoding)
|
|
586 (delete-region (point-min) (point-max))
|
|
587
|
|
588 (insert
|
|
589 ;; Just ASCII.
|
|
590 #r" (defvar testing-mule-compilation-handling
|
|
591 (string ?A)) ;; LATIN CAPITAL LETTER A")
|
|
592
|
|
593 (Assert-elc-has-no-specified-encoding)
|
|
594 (delete-region (point-min) (point-max))))
|
434
|
595 )
|