1 ;;; ccl-tests.el --- Testsuites on CCL ; -*- coding: iso-2022-7bit -*-
3 ;; Copyright (C) 2000 MIYASHITA Hisashi
5 ;; This file is part of SXEmacs.
7 ;; SXEmacs is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by the
9 ;; Free Software Foundation, either version 3 of the License, or (at your
10 ;; option) any later version.
12 ;; SXEmacs is distributed in the hope that it will be
13 ;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; 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 <http://www.gnu.org/licenses/>.
20 ;;; Section 0. Useful functions to construct test suites.
22 (defvar ccl-test-last-register-state nil)
24 (defun ccl-test-register-ccl-program (sym prog)
25 (let ((compiled (ccl-compile prog)))
26 (register-ccl-program sym compiled)
29 (defun ccl-test (prog &optional regs return-reg-idx)
30 (ccl-test-register-ccl-program
32 (cond ((< (length regs) 8)
33 (setq ccl-test-last-register-state
34 (apply #'vector (append regs (make-list (- 8 (length regs)) 0)))))
36 (setq ccl-test-last-register-state
37 (apply #'vector (subseq regs 0 8))))
39 (setq ccl-test-last-register-state
40 (apply #'vector regs))))
43 ccl-test-last-register-state)
44 (if (null return-reg-idx)
45 (setq return-reg-idx 0))
46 (aref ccl-test-last-register-state return-reg-idx))
48 (defun ccl-test-on-stream (prog string
49 &optional not-check-coding-system)
50 (ccl-test-register-ccl-program
51 'ccl-test-decoder prog)
52 (setq ccl-test-last-register-state (make-vector 9 0))
54 (ccl-execute-on-string
56 ccl-test-last-register-state
58 (if (not not-check-coding-system)
62 string 'ccl-test-coding-system))))
65 (defvar ccl-test-symbol-idx 0)
66 (defun ccl-test-generate-symbol (idx)
67 (intern (format "ccl-test-map-sym-%d" idx)))
69 (defun ccl-test-construct-map-structure (maps &optional idx)
70 (setq ccl-test-symbol-idx (if idx idx 0))
76 (setq sym (ccl-test-generate-symbol
79 (1+ ccl-test-symbol-idx))
80 (register-code-conversion-map
83 (setq result (cons sym result)))
86 (setq result (cons sym result)))
90 (cons (ccl-test-construct-map-structure
91 map ccl-test-symbol-idx)
94 (error "Unknown data:%S" map))))
97 (defun ccl-test-map-multiple (val maps)
101 ,(ccl-test-construct-map-structure maps))))
103 (cons (aref ccl-test-last-register-state 0)
104 (aref ccl-test-last-register-state 1)))
106 (defun ccl-test-iterate-multiple-map (val maps)
108 `(0 ((iterate-multiple-map
110 ,@(ccl-test-construct-map-structure maps))))
112 (cons (aref ccl-test-last-register-state 0)
113 (aref ccl-test-last-register-state 1)))
115 (defun ccl-test-setup ()
120 (write-read-repeat r0))))
125 (write-read-repeat r0))))
127 'ccl-test-coding-system
129 "CCL TEST temprary coding-system."
130 '(mnemonic "CCL-TEST"
132 decode ccl-test-decoder
133 encode ccl-test-encoder)))
135 ;;; Section 1. arithmetic operations.
137 (defun ccl-test-normal-expr ()
139 (let ((r0 0) (r1 10) (r2 20) (r3 21) (r4 7))
140 (Assert (= (ccl-test '(0 ((r0 = ((((r1 * r2) + r3) % r4) << 2))))
141 (list r0 r1 r2 r3 r4))
142 (ash (% (+ (* r1 r2) r3) r4) 2))))
144 (Assert (\= (ccl-test '(0 ((r2 = (r1 < 10))
149 (let ((r0 0) (r1 #x10FF) (r2 #xCC) (r3 #xE0))
150 (Assert (= (ccl-test '(0 ((r0 = (((r1 & #xFF) ^ r2) | r3))))
152 (logior (logxor (logand r1 #xFF) r2) r3))))
154 ;; checking range of SJIS
155 ;; 81(40-7E, 80-FC), 82, 9F, E0, E1, EF
157 (let ((hs '(#x81 #x82 #x9F #xE0 #xE1 #xEF))
162 (setq ch (split-char (decode-shift-jis-char
166 (ccl-test '(0 ((r0 = (r1 de-sjis r2))))
168 (Assert (and (= c1 (aref ccl-test-last-register-state 0))
169 (= c2 (aref ccl-test-last-register-state 7))))
170 (ccl-test '(0 ((r0 = (r1 en-sjis r2))))
172 (Assert (and (= high (aref ccl-test-last-register-state 0))
173 (= low (aref ccl-test-last-register-state 7)))))))
174 (while (setq high (car hs))
178 (funcall func high low)
182 (funcall func high low)
183 (setq low (1+ low)))))
186 (Assert (= (ccl-test '(0 ((r0 += 20)
190 (- (* (+ 100 20) 40) 15)))
193 (Assert (= (ccl-test '(0 ((r0 = r0 [100 101 102 103 104])))
197 ;;; Section 2. Simple read and write
198 (defun ccl-test-simple-read-and-write ()
200 (let* ((str "1234567890abcdefghij")
201 (dum (make-string 1 ?X)))
203 (string= (ccl-test-on-stream
205 ((loop (read r0) (write ,str)))) dum)
208 (let* ((str "1234567890abcdefghij"))
210 (string= (ccl-test-on-stream `(1 ((read r0)
218 (string= (ccl-test-on-stream `(1 ((read r0)
220 (write-read-repeat r0))))
225 (let ((str "1234567890abcdefghij")
231 (setq str2 (concat str2 (char-to-string
232 (+ (char-to-int (aref str i)) 3))))
235 (string= (ccl-test-on-stream `(1 ((read r0)
243 (string= (ccl-test-on-stream `(1 ((read r0)
246 (write-read-repeat r0))))
252 (let* ((str (mapconcat (lambda (x) (char-to-string (int-to-char x)))
253 '(0 1 2 3 4 5 6) "")))
255 (string= (ccl-test-on-stream
259 ,(vector (make-char 'japanese-jisx0208 36 34)
260 (make-char 'japanese-jisx0208 36 36)
261 (make-char 'japanese-jisx0208 36 38)
262 (make-char 'japanese-jisx0208 36 40)
263 (make-char 'japanese-jisx0208 36 42)
264 (make-char 'japanese-jisx0208 36 43)
265 (make-char 'japanese-jisx0208 36 45)
266 (make-char 'japanese-jisx0208 36 47)
267 (make-char 'japanese-jisx0208 36 49)
268 (make-char 'japanese-jisx0208 36 51)))
272 (mapconcat #'char-to-string
273 (list (make-char 'japanese-jisx0208 36 34)
274 (make-char 'japanese-jisx0208 36 36)
275 (make-char 'japanese-jisx0208 36 38)
276 (make-char 'japanese-jisx0208 36 40)
277 (make-char 'japanese-jisx0208 36 42)
278 (make-char 'japanese-jisx0208 36 43)
279 (make-char 'japanese-jisx0208 36 45))
282 ;;; Section 3. read-multibyte-character, and write-multibyte-character
283 (defun ccl-test-read-write-multibyte-character ()
285 (let* ((str (concat "LMDXXX..."
286 (mapconcat #'char-to-string
287 (list (make-char 'japanese-jisx0208 36 36)
288 (make-char 'japanese-jisx0208 36 36)
289 (make-char 'japanese-jisx0208 50 67)
290 (make-char 'japanese-jisx0208 56 58)
291 (make-char 'japanese-jisx0208 72 104)
292 (make-char 'japanese-jisx0208 36 108)
293 (make-char 'japanese-jisx0208 36 70)
294 (make-char 'japanese-jisx0208 36 45)
295 (make-char 'japanese-jisx0208 36 63)
296 (make-char 'japanese-jisx0208 33 35))
303 (read-multibyte-character r0 r1)
304 (write-multibyte-character r0 r1)
311 ;;; Section 4. CCL call
312 (defun ccl-test-ccl-call ()
321 ((call ccl-test-sub1)
326 ((call ccl-test-sub2)
331 '(1 ((loop (read r0) (call ccl-test-sub3))))
335 ;;; Section 5. Map-instructions
336 (defun ccl-test-map-instructions ()
358 ;; 1-level normal 1 mapping
362 (ccl-test-map-multiple
365 '(0 99 100 101 102 103 104 105 106 107))
367 (1 . 0) (2 . 0) (3 . 0) (4 . 0) (5 . 0)
368 (105 . -1) (106 . -1) (107 . -1))))
373 (ccl-test-iterate-multiple-map
376 '(0 99 100 101 102 103 104 105 106 107))
378 (1 . 0) (2 . 0) (3 . 0) (4 . 0) (5 . 0)
379 (105 . -1) (106 . -1) (107 . -1))))
381 ;; 1-level normal 2 mappings
385 (ccl-test-map-multiple
388 [101 12 13 14 15 16 17])))
389 '(0 99 100 101 102 103 104 105 106 107))
390 '((0 . -1) (99 . -1) (1 . 0) (2 . 0)
391 (13 . 1) (4 . 0) (5 . 0) (16 . 1) (17 . 1)
397 (ccl-test-iterate-multiple-map
400 [101 12 13 14 15 16 17])))
401 '(0 99 100 101 102 103 104 105 106 107))
402 '((0 . -1) (99 . -1) (1 . 0) (2 . 0) (3 . 0)
403 (4 . 0) (5 . 0) (16 . 1) (17 . 1) (107 . -1))))
406 ;; 1-level normal 7 mappings
410 (ccl-test-map-multiple
413 [101 12 13 14 15 16 17]
414 [1000 101 102 103 nil 105 106 nil 108]
415 [1005 1006 1007 1008 1009 1010 1011 1012]
416 [10005 10006 10007 10008 10009 10010 10011 10012]
417 [20000 20000 20001 20002 nil 20004 20005 20006]
418 [20003 30000 30010 30020 30030 30040 30050 30060]
420 '(0 99 100 101 102 103 104 105 106 107
421 998 999 1000 1001 1002 1003 1004 1005 1006 1007
422 9999 10000 10001 10002 10003 10004
423 19999 20000 20001 20002 20003 20004
425 '((0 . -1) (99 . -1) (1 . 0) (2 . 0) (13 . 1) (4 . 0)
426 (5 . 0) (16 . 1) (17 . 1) (107 . -1) (998 . -1)
427 (999 . -1) (101 . 2) (102 . 2) (103 . 2) (1003 . -1)
428 (105 . 2) (106 . 2) (1007 . 3) (108 . 2) (9999 . -1)
429 (10000 . -1) (10001 . -1) (10002 . -1) (10003 . -1)
430 (10004 . -1) (19999 . -1) (20000 . 5) (20001 . 5)
431 (20002 . 5) (30000 . 6) (20004 . 5) (20005 . 5) (20006 . 5))))
436 (ccl-test-iterate-multiple-map
439 [101 12 13 14 15 16 17]
440 [1000 101 102 103 nil 105 106 nil 108]
441 [1005 1006 1007 1008 1009 1010 1011 1012]
442 [10005 10006 10007 10008 10009 10010 10011 10012]
443 [20000 20000 20001 20002 nil 20004 20005 20006]
444 [20003 30000 30010 30020 30030 30040 30050 30060]
446 '(0 99 100 101 102 103 104 105 106 107
447 998 999 1000 1001 1002 1003 1004 1005 1006 1007
448 9999 10000 10001 10002 10003 10004
449 19999 20000 20001 20002 20003 20004
451 '((0 . -1) (99 . -1) (1 . 0) (2 . 0) (13 . 1) (4 . 0)
452 (5 . 0) (16 . 1) (17 . 1) (107 . -1) (998 . -1)
453 (999 . -1) (101 . 2) (102 . 2) (103 . 2) (1003 . -1)
454 (105 . 2) (106 . 2) (1007 . 3) (108 . 2) (9999 . -1)
455 (10000 . -1) (10001 . -1) (10002 . -1) (10003 . -1)
456 (10004 . -1) (19999 . -1) (20000 . 5) (20001 . 5)
457 (20002 . 5)(30000 . 6)(20004 . 5)(20005 . 5)(20006 . 5))))
459 ;; 1-level 7 mappings including CCL call
464 (ccl-test-map-multiple
467 [101 12 13 14 15 16 17]
468 [1000 101 ccl-test-arith-1 103 nil 105 106 ccl-test-nil 108]
469 [1005 1006 1007 1008 1009 ccl-test-lambda 1011 1012]
470 [10005 10006 10007 10008 10009 10010 10011 10012]
471 [20000 20000 20001 20002 nil 20004 20005 20006]
472 [20003 30000 30010 30020 30030 30040 30050 30060]
474 '(0 99 100 101 102 103 104 105 106 107
475 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
476 9999 10000 10001 10002 10003 10004
477 19999 20000 20001 20002 20003 20004
479 '((0 . -1) (99 . -1) (1 . 0) (2 . 0) (13 . 1) (4 . 0)
480 (5 . 0) (16 . 1) (17 . 1) (107 . -1) (998 . -1)
481 (999 . -1) (101 . 2) (1001001 . 2) (103 . 2)
482 (1003 . -1) (105 . 2) (106 . 2) (1007 . 3) (108 . 2)
483 (1009 . 3) (1009 . 3) (9999 . -1) (10000 . -1)
484 (10001 . -1) (10002 . -1) (10003 . -1) (10004 . -1)
485 (19999 . -1) (20000 . 5) (20001 . 5) (20002 . 5)
486 (30000 . 6)(20004 . 5)(20005 . 5)(20006 . 5))))
491 (ccl-test-iterate-multiple-map
494 [101 12 13 14 15 16 17]
495 [1000 101 ccl-test-arith-1 103 nil 105 106 ccl-test-nil 108]
496 [1005 1006 1007 1008 1009 ccl-test-lambda 1011 1012]
497 [10005 10006 10007 10008 10009 10010 10011 10012]
498 [20000 20000 20001 20002 nil 20004 20005 20006]
499 [20003 30000 30010 30020 30030 30040 30050 30060]
501 '(0 99 100 101 102 103 104 105 106 107
502 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
503 9999 10000 10001 10002 10003 10004
504 19999 20000 20001 20002 20003 20004
506 '((0 . -1) (99 . -1) (1 . 0) (2 . 0) (13 . 1) (4 . 0)
507 (5 . 0) (16 . 1) (17 . 1) (107 . -1) (998 . -1)
508 (999 . -1) (101 . 2) (1001001 . 0) (103 . 2)
509 (1003 . -1) (105 . 2) (106 . 2) (-1 . 0) (108 . 2)
510 (1009 . 3) (-3 . 0) (9999 . -1) (10000 . -1)
511 (10001 . -1) (10002 . -1) (10003 . -1) (10004 . -1)
512 (19999 . -1) (20000 . 5) (20001 . 5) (20002 . 5)
513 (30000 . 6) (20004 . 5) (20005 . 5) (20006 . 5))))
519 (ccl-test-map-multiple
522 [101 12 13 14 15 16 17]
523 [1000 101 102 103 nil 105 106 nil 108]
524 (([1005 1006 1007 1008 1009 1010 1011 1012]
525 [10005 10006 20007 20008 10009 10010 10011 10012])
526 [20000 20000 20001 20002 nil 20004 20005 20006]
527 [1006 2006 2007 2008 2009 2010]
528 ([20003 30000 30010 30020 30030 30040 30050 30060]))
530 [1008 1108 1109 1110 1111 1112 1113])))
531 '(0 99 100 101 102 103 104 105 106 107
532 998 999 1000 1001 1002 1003 1004 1005 1006 1007
533 1008 1009 1010 1011 1012 1013 1014
534 9999 10000 10001 10002 10003 10004
535 10005 10006 10007 10008 10009 10010
536 19999 20000 20001 20002 20003 20004
538 '((0 . 11) (99 . 11) (1 . 0) (2 . 0) (13 . 1)
539 (4 . 0) (5 . 0) (16 . 1) (17 . 1) (107 . 11)
540 (998 . 11) (999 . 11) (101 . 2) (102 . 2)
541 (103 . 2) (1003 . 11) (105 . 2) (106 . 2)
542 (1006 . 11) (108 . 2) (1108 . 12) (1109 . 12)
543 (1110 . 12) (1111 . 12) (1112 . 12) (1113 . 12)
544 (1014 . 11) (9999 . 11) (10000 . 11) (10001 . 11)
545 (10002 . 11) (10003 . 11) (10004 . 11) (10005 . 11)
546 (30040 . 10) (30050 . 10) (10008 . 11) (10009 . 11)
547 (10010 . 11) (19999 . 11) (20000 . 11) (20001 . 11)
548 (20002 . 11) (20003 . 11) (20004 . 11) (20005 . 11)
552 ;; 3-level mappings including CCL call
556 (ccl-test-map-multiple
559 [101 12 13 14 15 16 17]
560 [1000 101 102 103 nil ccl-test-arith-1 106 nil 108]
561 (([1005 1006 1007 1008 1009 1010 1011 ccl-test-arith-1
563 [10005 10006 20007 20008 10009 10010 10011 10012])
564 [70 ccl-test-t ccl-test-lambda ccl-test-nil ccl-test-nil]
566 [20000 20000 20001 20002 nil 20004 20005 20006]
567 [1006 2006 2007 2008 2009 2010]
568 ([20003 30000 30010 ccl-test-arith-1 30030 30040
569 ccl-test-arith-1 30060]
570 [1001010 50 51 52 53 54 55]))
572 [t ccl-test-arith-1 0 10]
573 [1008 1108 1109 1110 1111 1112 1113])))
574 '(0 99 100 101 102 103 104 105 106 107
575 998 999 1000 1001 1002 1003 1004 1005 1006 1007
576 1008 1009 1010 1011 1012 1013 1014 1015 1016
577 9999 10000 10001 10002 10003 10004
578 10005 10006 10007 10008 10009 10010
579 19999 20000 20001 20002 20003 20004
581 '((1000000 . 15) (99 . 14) (1 . 0) (2 . 0) (13 . 1)
582 (4 . 0) (5 . 0) (16 . 1) (17 . 1) (107 . 14) (998 . 14)
583 (999 . 14) (101 . 2) (102 . 2) (103 . 2) (1003 . 14)
584 (1001004 . 2) (106 . 2) (1006 . 14) (108 . 2) (1108 . 16)
585 (1109 . 16) (1110 . 16) (51 . 13) (1112 . 16) (71 . 7)
586 (72 . 8) (1015 . 14) (1016 . 14) (9999 . 14) (10000 . 14)
587 (10001 . 14) (10002 . 14) (10003 . 14) (10004 . 14)
588 (10005 . 14) (30040 . 12) (1020008 . 12) (10008 . 14)
589 (10009 . 14) (10010 . 14) (19999 . 14) (20000 . 14)
590 (20001 . 14) (20002 . 14) (20003 . 14) (20004 . 14)
591 (20005 . 14) (20006 . 14))))
592 ;; All map-instruction tests ends here.
595 (defun ccl-test-suites ()
597 (ccl-test-normal-expr)
598 (ccl-test-simple-read-and-write)
599 (ccl-test-read-write-multibyte-character)
601 (ccl-test-map-instructions))
603 ;;; start tests only when ccl-execute is enabled.
604 (if (fboundp 'ccl-execute)
607 ;;; ccl-test.el ends here.