1 ;;; -*- coding: utf-8 -*-
2 ;;; enc-cn.impure.lisp: test case for enc-cn.lisp and enc-cn-tbl.lisp
4 (sb-ext:exit
:code
104)
6 ;; use "1AAあ胡玥姮" for tests
7 (let ((str (coerce '(#\u0031 #\u0041 #\uff21 #\u3042 #\u80e1 #\u73a5 #\u59ee)
9 (gbk '(#x31
#x41
#xa3
#xc1
#xa4
#xa2
#xba
#xfa
#xab
#x68
#x8a
#xac
))
10 (file "enc-cn-test.txt"))
11 (dolist (pair (list (list gbk
:gbk
)))
12 (destructuring-bind (bytes enc
) pair
13 ;; check if output works
14 (with-open-file (s file
:direction
:output
15 :if-exists
:supersede
:external-format enc
)
17 (with-open-file (s file
:direction
:input
18 :element-type
'(unsigned-byte 8))
20 do
(assert (eql (read-byte s
) c
))))
22 ;; check if input works
23 (with-open-file (s file
:direction
:input
:external-format enc
)
24 (loop for c across str
25 do
(assert (eql (read-char s
) c
))))
27 ;; check if string conversion works
28 (assert (equal (coerce (string-to-octets str
:external-format enc
)
31 (assert (equal (octets-to-string (coerce bytes
32 '(vector (unsigned-byte 8)))