X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Foctets.pure.lisp;h=d40b26095877c393b4fb8d0336531dc3ebe84fda;hb=d5e1f093b8ca643ce4f39554232e0a1688e85b7c;hp=1a276a7963367dca3295f36f7d93cd521e4d7a56;hpb=99a8f9e012fd2b5edc9a0927edfc537332081997;p=sbcl.git diff --git a/tests/octets.pure.lisp b/tests/octets.pure.lisp index 1a276a7..d40b260 100644 --- a/tests/octets.pure.lisp +++ b/tests/octets.pure.lisp @@ -315,3 +315,91 @@ (assert (equalp (octets-to-string (coerce '(#x00 #x10 #xff #xff) '(vector (unsigned-byte 8))) :external-format :ucs-4be) (string (code-char #x10ffff)))))) + +#+sb-unicode +(with-test (:name (:utf-16le :ensure-roundtrip)) + (flet ((enc (x) + (string-to-octets x :external-format :utf-16le)) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-16le))) + (let ((string (map 'string 'code-char + '(#x20 #x200 #x2000 #x10000 #x10401 #x10fffd))) + (octets #(#x20 0 0 #x2 0 #x20 0 #xd8 0 #xdc 1 #xd8 1 #xdc #xff #xdb #xfd #xdf))) + (assert (equalp (enc string) octets)) + (assert (equalp (dec octets) string))))) +#+sb-unicode +(with-test (:name (:utf-16le :encoding-error)) + (flet ((enc (x) + (string-to-octets x :external-format '(:utf-16le :replacement #\?))) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-16le))) + (let ((string (map 'string 'code-char '(#xd800 #xdc00 #xfffe #x10ffff)))) + (assert (equalp (enc string) #(63 0 63 0 63 0 63 0)))))) + +#+sb-unicode +(with-test (:name (:utf-16be :ensure-roundtrip)) + (flet ((enc (x) + (string-to-octets x :external-format :utf-16be)) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-16be))) + (let ((string (map 'string 'code-char + '(#x20 #x200 #x2000 #x10000 #x10401 #x10fffd))) + (octets #(0 #x20 #x2 0 #x20 0 #xd8 0 #xdc 0 #xd8 1 #xdc 1 #xdb #xff #xdf #xfd))) + (assert (equalp (enc string) octets)) + (assert (equalp (dec octets) string))))) +#+sb-unicode +(with-test (:name (:utf-16be :encoding-error)) + (flet ((enc (x) + (string-to-octets x :external-format '(:utf-16be :replacement #\?))) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-16be))) + (let ((string (map 'string 'code-char '(#xd800 #xdc00 #xfffe #x10ffff)))) + (assert (equalp (enc string) #(0 63 0 63 0 63 0 63)))))) + +#+sb-unicode +(with-test (:name (:utf-32le :ensure-roundtrip)) + (flet ((enc (x) + (string-to-octets x :external-format :utf-32le)) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-32le))) + (let ((string (map 'string 'code-char + '(#x20 #x200 #x2000 #x10000 #x10401 #x10fffd))) + (octets #(#x20 0 0 0 0 #x2 0 0 0 #x20 0 0 0 0 1 0 1 4 1 0 #xfd #xff #x10 0))) + (assert (equalp (enc string) octets)) + (assert (equalp (dec octets) string))))) +#+sb-unicode +(with-test (:name (:utf-32le :encoding-error)) + (flet ((enc (x) + (string-to-octets x :external-format '(:utf-32le :replacement #\?))) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-32le))) + (let ((string (map 'string 'code-char '(#xd800 #xdc00 #xfffe #x10ffff)))) + (assert (equalp (enc string) #(63 0 0 0 63 0 0 0 63 0 0 0 63 0 0 0)))))) + +#+sb-unicode +(with-test (:name (:utf-32be :ensure-roundtrip)) + (flet ((enc (x) + (string-to-octets x :external-format :utf-32be)) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-32be))) + (let ((string (map 'string 'code-char + '(#x20 #x200 #x2000 #x10000 #x10401 #x10fffd))) + (octets #(0 0 0 #x20 0 0 #x2 0 0 0 #x20 0 0 1 0 0 0 1 4 1 0 #x10 #xff #xfd))) + (assert (equalp (enc string) octets)) + (assert (equalp (dec octets) string))))) +#+sb-unicode +(with-test (:name (:utf-32be :encoding-error)) + (flet ((enc (x) + (string-to-octets x :external-format '(:utf-32be :replacement #\?))) + (dec (x) + (octets-to-string (coerce x '(vector (unsigned-byte 8))) + :external-format :utf-32be))) + (let ((string (map 'string 'code-char '(#xd800 #xdc00 #xfffe #x10ffff)))) + (assert (equalp (enc string) #(0 0 0 63 0 0 0 63 0 0 0 63 0 0 0 63))))))