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 ;;---------------------------------------------------------------
|
|
330 (let* ((scaron (make-char 'latin-iso8859-2 57))
|
|
331 (latin2-string (make-string 4 scaron))
|
597
|
332 (prefix (concat (file-name-as-directory
|
|
333 (file-truename (temp-directory)))
|
|
334 latin2-string))
|
442
|
335 (name1 (make-temp-name prefix))
|
|
336 (name2 (make-temp-name prefix))
|
2026
|
337 (file-name-coding-system
|
|
338 ;; 'iso-8859-X doesn't work on darwin (as of "Panther" 10.3), it
|
|
339 ;; seems to know that file-name-coding-system is definitely utf-8
|
|
340 (if (string-match "darwin" system-configuration)
|
|
341 'utf-8
|
|
342 'iso-8859-2))
|
|
343 )
|
3472
|
344 (Assert (not (equal name1 name2)))
|
|
345 (Assert (not (file-exists-p name1)))
|
3952
|
346 ;; This is how you suppress output from `message', called by `write-region'
|
3472
|
347 (Silence-Message
|
|
348 (write-region (point-min) (point-max) name1))
|
|
349 (Assert (file-exists-p name1))
|
|
350 (when (fboundp 'make-symbolic-link)
|
|
351 (make-symbolic-link name1 name2)
|
|
352 (Assert (file-exists-p name2))
|
|
353 (Assert (equal (file-truename name2) name1))
|
|
354 (Assert (equal (file-truename name1) name1)))
|
442
|
355
|
3472
|
356 (ignore-file-errors (delete-file name1) (delete-file name2)))
|
442
|
357
|
|
358 ;; Add many more file operation tests here...
|
|
359
|
|
360 ;;---------------------------------------------------------------
|
|
361 ;; Test Unicode-related functions
|
|
362 ;;---------------------------------------------------------------
|
|
363 (let* ((scaron (make-char 'latin-iso8859-2 57)))
|
875
|
364 ;; Used to try #x0000, but you can't change ASCII or Latin-1
|
|
365 (loop for code in '(#x0100 #x2222 #x4444 #xffff) do
|
442
|
366 (progn
|
800
|
367 (set-unicode-conversion scaron code)
|
|
368 (Assert (eq code (char-to-unicode scaron)))
|
|
369 (Assert (eq scaron (unicode-to-char code '(latin-iso8859-2))))))
|
442
|
370
|
800
|
371 (Check-Error wrong-type-argument (set-unicode-conversion scaron -10000)))
|
1195
|
372
|
3439
|
373 (dolist (utf-8-char
|
|
374 '("\xc6\x92" ;; U+0192 LATIN SMALL LETTER F WITH HOOK
|
|
375 "\xe2\x81\x8a" ;; U+204A TIRONIAN SIGN ET
|
|
376 "\xe2\x82\xae" ;; U+20AE TUGRIK SIGN
|
|
377 "\xf0\x9d\x92\xbd" ;; U+1D4BD MATHEMATICAL SCRIPT SMALL H
|
|
378 "\xf0\x9d\x96\x93" ;; U+1D593 MATHEMATICAL BOLD FRAKTUR SMALL N
|
|
379 "\xf0\xaf\xa8\x88" ;; U+2FA08 CJK COMPATIBILITY FOR U+4BCE
|
|
380 "\xf4\x8f\xbf\xbd")) ;; U+10FFFD <Plane 16 Private Use, Last>
|
|
381 (let* ((xemacs-character (car (append
|
|
382 (decode-coding-string utf-8-char 'utf-8)
|
|
383 nil)))
|
|
384 (xemacs-charset (car (split-char xemacs-character))))
|
|
385
|
|
386 ;; Trivial test of the UTF-8 support of the escape-quoted character set.
|
|
387 (Assert (equal (decode-coding-string utf-8-char 'utf-8)
|
|
388 (decode-coding-string (concat "\033%G" utf-8-char)
|
|
389 'escape-quoted)))
|
|
390
|
|
391 ;; Check that the reverse mapping holds.
|
|
392 (Assert (equal (unicode-code-point-to-utf-8-string
|
|
393 (encode-char xemacs-character 'ucs))
|
|
394 utf-8-char))
|
|
395
|
|
396 ;; Check that, if this character has been JIT-allocated, it is encoded
|
|
397 ;; in escape-quoted using the corresponding UTF-8 escape.
|
|
398 (when (charset-property xemacs-charset 'encode-as-utf-8)
|
|
399 (Assert (equal (concat "\033%G" utf-8-char)
|
|
400 (encode-coding-string xemacs-character 'escape-quoted)))
|
|
401 (Assert (equal (concat "\033%G" utf-8-char)
|
|
402 (encode-coding-string xemacs-character 'ctext))))))
|
|
403
|
3952
|
404 (loop
|
|
405 for (code-point encoded)
|
|
406 in '((#x10000 "\xd8\x00\xdc\x00")
|
|
407 (#x10FFFD "\xdb\xff\xdf\xfd"))
|
|
408 do (Assert (equal (encode-coding-string
|
|
409 (decode-char 'ucs code-point) 'utf-16)
|
|
410 encoded)))
|
|
411
|
1195
|
412 ;;---------------------------------------------------------------
|
3690
|
413 ;; Regression test for a couple of CCL-related bugs.
|
|
414 ;;---------------------------------------------------------------
|
|
415
|
|
416 (let ((ccl-vector [0 0 0 0 0 0 0 0 0]))
|
|
417 (define-ccl-program ccl-write-two-control-1-chars
|
|
418 `(1
|
|
419 ((r0 = ,(charset-id 'control-1))
|
|
420 (r1 = 0)
|
|
421 (write-multibyte-character r0 r1)
|
|
422 (r1 = 31)
|
|
423 (write-multibyte-character r0 r1)))
|
|
424 "CCL program that writes two control-1 multibyte characters.")
|
|
425
|
|
426 (Assert (equal
|
|
427 (ccl-execute-on-string 'ccl-write-two-control-1-chars
|
|
428 ccl-vector "")
|
|
429 (format "%c%c" (make-char 'control-1 0)
|
|
430 (make-char 'control-1 31))))
|
|
431
|
|
432 (define-ccl-program ccl-unicode-two-control-1-chars
|
|
433 `(1
|
|
434 ((r0 = ,(charset-id 'control-1))
|
|
435 (r1 = 31)
|
|
436 (mule-to-unicode r0 r1)
|
|
437 (r4 = r0)
|
|
438 (r3 = ,(charset-id 'control-1))
|
|
439 (r2 = 0)
|
|
440 (mule-to-unicode r3 r2)))
|
|
441 "CCL program that writes two control-1 UCS code points in r3 and r4")
|
|
442
|
|
443 ;; Re-initialise the vector, mainly to clear the instruction counter,
|
|
444 ;; which is its last element.
|
|
445 (setq ccl-vector [0 0 0 0 0 0 0 0 0])
|
|
446
|
|
447 (ccl-execute-on-string 'ccl-unicode-two-control-1-chars ccl-vector "")
|
|
448
|
|
449 (Assert (and (eq (aref ccl-vector 3)
|
|
450 (encode-char (make-char 'control-1 0) 'ucs))
|
|
451 (eq (aref ccl-vector 4)
|
|
452 (encode-char (make-char 'control-1 31) 'ucs)))))
|
|
453
|
|
454 ;;---------------------------------------------------------------
|
1195
|
455 ;; Test charset-in-* functions
|
|
456 ;;---------------------------------------------------------------
|
|
457 (with-temp-buffer
|
|
458 (insert-file-contents (locate-data-file "HELLO"))
|
3927
|
459 (Assert (equal
|
|
460 ;; The sort is to make the algorithm of charsets-in-region
|
|
461 ;; irrelevant.
|
|
462 (sort (charsets-in-region (point-min) (point-max))
|
|
463 'string<)
|
|
464 '(arabic-1-column arabic-2-column ascii chinese-big5-1
|
|
465 chinese-gb2312 cyrillic-iso8859-5 ethiopic greek-iso8859-7
|
|
466 hebrew-iso8859-8 japanese-jisx0208 japanese-jisx0212
|
|
467 katakana-jisx0201 korean-ksc5601 latin-iso8859-1
|
|
468 latin-iso8859-2 thai-xtis vietnamese-viscii-lower)))
|
|
469 (Assert (equal
|
|
470 (sort (charsets-in-string (buffer-substring (point-min)
|
1316
|
471 (point-max)))
|
3927
|
472 'string<)
|
|
473 '(arabic-1-column arabic-2-column ascii chinese-big5-1
|
|
474 chinese-gb2312 cyrillic-iso8859-5 ethiopic greek-iso8859-7
|
|
475 hebrew-iso8859-8 japanese-jisx0208 japanese-jisx0212
|
|
476 katakana-jisx0201 korean-ksc5601 latin-iso8859-1
|
|
477 latin-iso8859-2 thai-xtis vietnamese-viscii-lower))))
|
3948
|
478
|
|
479 (with-temp-buffer
|
|
480 (flet
|
|
481 ((Assert-elc-is-escape-quoted ()
|
|
482 "Assert the current buffer has an escape-quoted cookie if compiled."
|
|
483 (save-excursion
|
|
484 (let ((byte-compile-result (byte-compile-from-buffer
|
|
485 (current-buffer) nil nil))
|
|
486 (temporary-file-name (make-temp-name
|
|
487 (expand-file-name "zjPQ2Pk"
|
|
488 (temp-directory)))))
|
|
489 (byte-compile-insert-header
|
|
490 temporary-file-name
|
|
491 (current-buffer)
|
|
492 byte-compile-result)
|
|
493 (Assert (string-match "^;;;###coding system: escape-quoted"
|
|
494 (buffer-substring nil nil
|
|
495 byte-compile-result))))))
|
|
496 (Assert-elc-has-no-specified-encoding ()
|
|
497 "Assert the current buffer has no coding cookie if compiled."
|
|
498 (save-excursion
|
|
499 (let ((byte-compile-result (byte-compile-from-buffer
|
|
500 (current-buffer) nil nil))
|
|
501 (temporary-file-name (make-temp-name
|
|
502 (expand-file-name "zjPQ2Pk"
|
|
503 (temp-directory)))))
|
|
504 (byte-compile-insert-header
|
|
505 temporary-file-name
|
|
506 (current-buffer)
|
|
507 byte-compile-result)
|
|
508 (Assert (not (string-match
|
|
509 ";;;###coding system:"
|
|
510 (buffer-substring nil nil byte-compile-result))))))))
|
|
511 (insert
|
|
512 ;; Create a buffer creating the Unicode escapes.
|
|
513 #r" (defvar testing-mule-compilation-handling
|
|
514 (string ?\u371E ;; kDefinition beautiful; pretty, used
|
|
515 ;; in girl's name
|
|
516 ?\U0002A6A9 ;; kDefinition (Cant.) sound of shouting
|
|
517 ?\U0002A65B ;; kDefinition (Cant.) decayed teeth;
|
|
518 ;; tongue-tied
|
|
519 ?\U00010400 ;; DESERET CAPITAL LETTER LONG I
|
|
520 ?\u3263)) ;; CIRCLED HANGUL RIEUL ")
|
|
521
|
|
522 (Assert-elc-is-escape-quoted)
|
|
523 (delete-region (point-min) (point-max))
|
|
524
|
|
525 (insert
|
|
526 ;; This time, the buffer will contain the actual characters, because of
|
|
527 ;; u flag to the #r.
|
|
528 #ru" (defvar testing-mule-compilation-handling
|
|
529 (string ?\u371E ;; kDefinition beautiful; pretty, used
|
|
530 ;; in girl's name
|
|
531 ?\U0002A6A9 ;; kDefinition (Cant.) sound of shouting
|
|
532 ?\U0002A65B ;; kDefinition (Cant.) decayed teeth;
|
|
533 ;; tongue-tied
|
|
534 ?\U00010400 ;; DESERET CAPITAL LETTER LONG I
|
|
535 ?\u3263)) ;; CIRCLED HANGUL RIEUL ")
|
|
536
|
|
537 (Assert-elc-is-escape-quoted)
|
|
538 (delete-region (point-min) (point-max))
|
|
539
|
|
540 (insert
|
|
541 ;; Just a single four character escape.
|
|
542 #r" (defvar testing-mule-compilation-handling
|
|
543 (string ?\u371E)) ;; kDefinition beautiful; pretty, used")
|
|
544
|
|
545 (Assert-elc-is-escape-quoted)
|
|
546 (delete-region (point-min) (point-max))
|
|
547
|
|
548 (insert
|
|
549 ;; Just a single eight character escape.
|
|
550 #r" (defvar testing-mule-compilation-handling
|
|
551 (string ?\U0002A65B)) ;; kDefinition (Cant.) decayed teeth;")
|
|
552
|
|
553 (Assert-elc-is-escape-quoted)
|
|
554 (delete-region (point-min) (point-max))
|
|
555
|
|
556 (insert
|
|
557 ;; A single latin-1 hex digit escape
|
|
558 #r" (defvar testing-mule-compilation-handling
|
|
559 (string ?\xab)) ;; LEFT-POINTING DOUBLE ANGLE QUOTATION MARK")
|
|
560
|
|
561 (Assert-elc-has-no-specified-encoding)
|
|
562 (delete-region (point-min) (point-max))
|
|
563
|
|
564 (insert
|
|
565 ;; A single latin-1 character
|
|
566 #ru" (defvar testing-mule-compilation-handling
|
|
567 (string ?\u00AB)) ;; LEFT-POINTING DOUBLE ANGLE QUOTATION MARK")
|
|
568
|
|
569 (Assert-elc-has-no-specified-encoding)
|
|
570 (delete-region (point-min) (point-max))
|
|
571
|
|
572 (insert
|
|
573 ;; Just ASCII.
|
|
574 #r" (defvar testing-mule-compilation-handling
|
|
575 (string ?A)) ;; LATIN CAPITAL LETTER A")
|
|
576
|
|
577 (Assert-elc-has-no-specified-encoding)
|
|
578 (delete-region (point-min) (point-max))))
|
434
|
579 )
|