- (if (numberp len-or-seq)
- (make-array len-or-seq :element-type '(unsigned-byte 8) :initial-element 0)
- (coerce len-or-seq '(simple-array (unsigned-byte 8) (*)))))
-
- (ensure-roundtrip-ascii ()
- (let ((octets (ub8 128)))
- (dotimes (i 128)
- (setf (aref octets i) i))
- (let* ((str (octets-to-string octets :external-format :ascii))
- (oct2 (string-to-octets str :external-format :ascii)))
- (assert (= (length octets) (length oct2)))
- (assert (every #'= octets oct2))))
- t)
-
- (ensure-roundtrip-latin (format)
- (let ((octets (ub8 256)))
- (dotimes (i 256)
- (setf (aref octets i) i))
- (let* ((str (octets-to-string octets :external-format format))
- (oct2 (string-to-octets str :external-format format)))
- (assert (= (length octets) (length oct2)))
- (assert (every #'= octets oct2))))
- t)
-
- (ensure-roundtrip-latin1 ()
- (ensure-roundtrip-latin :latin1))
-
- #+sb-unicode
- (ensure-roundtrip-latin9 ()
- (ensure-roundtrip-latin :latin9))
-
- (ensure-roundtrip-utf8 ()
- (let ((string (make-string char-code-limit)))
- (dotimes (i char-code-limit)
- (setf (char string i) (code-char i)))
- (let ((string2
- (octets-to-string (string-to-octets string :external-format :utf8)
- :external-format :utf8)))
- (assert (= (length string2) (length string)))
- (assert (string= string string2))))
- t)
-
- (utf8-decode-test (octets expected-results expected-errors)
- (let ((error-count 0))
- (handler-bind ((sb-int:character-decoding-error
- (lambda (c)
- (incf error-count)
- (use-value "?" c))))
- (assert (string= expected-results
- (octets-to-string (ub8 octets)
- :external-format :utf-8)))
- (assert (= error-count expected-errors)))))
-
- (utf8-decode-tests (octets expected-results)
- (let ((expected-errors (count #\? expected-results)))
- (utf8-decode-test octets expected-results expected-errors)
- (utf8-decode-test (concatenate 'vector
- '(34)
- octets
- '(34))
- (format nil "\"~A\"" expected-results)
- expected-errors))))
-
+ (if (numberp len-or-seq)
+ (make-array len-or-seq :element-type '(unsigned-byte 8) :initial-element 0)
+ (coerce len-or-seq '(simple-array (unsigned-byte 8) (*)))))
+
+ (ensure-roundtrip-ascii ()
+ (let ((octets (ub8 128)))
+ (dotimes (i 128)
+ (setf (aref octets i) i))
+ (let* ((str (octets-to-string octets :external-format :ascii))
+ (oct2 (string-to-octets str :external-format :ascii)))
+ (assert (= (length octets) (length oct2)))
+ (assert (every #'= octets oct2))))
+ t)
+
+ (ensure-roundtrip-latin (format)
+ (let ((octets (ub8 256)))
+ (dotimes (i 256)
+ (setf (aref octets i) i))
+ (let* ((str (octets-to-string octets :external-format format))
+ (oct2 (string-to-octets str :external-format format)))
+ (assert (= (length octets) (length oct2)))
+ (assert (every #'= octets oct2))))
+ t)
+
+ (ensure-roundtrip-latin1 ()
+ (ensure-roundtrip-latin :latin1))
+
+ #+sb-unicode
+ (ensure-roundtrip-latin9 ()
+ (ensure-roundtrip-latin :latin9))
+
+ (ensure-roundtrip-utf8 ()
+ (let ((string (make-string char-code-limit)))
+ (dotimes (i char-code-limit)
+ (setf (char string i) (code-char i)))
+ (let ((string2
+ (octets-to-string (string-to-octets string :external-format :utf8)
+ :external-format :utf8)))
+ (assert (= (length string2) (length string)))
+ (assert (string= string string2))))
+ t)
+
+ (utf8-decode-test (octets expected-results expected-errors)
+ (let ((error-count 0))
+ (handler-bind ((sb-int:character-decoding-error
+ (lambda (c)
+ (incf error-count)
+ (use-value "?" c))))
+ (assert (string= expected-results
+ (octets-to-string (ub8 octets)
+ :external-format :utf-8)))
+ (assert (= error-count expected-errors)))))
+
+ (utf8-decode-tests (octets expected-results)
+ (let ((expected-errors (count #\? expected-results)))
+ (utf8-decode-test octets expected-results expected-errors)
+ (utf8-decode-test (concatenate 'vector
+ '(34)
+ octets
+ '(34))
+ (format nil "\"~A\"" expected-results)
+ expected-errors))))
+
- (apply #'utf8-decode-tests
- (loop for i from first to last
- nconc (list i 32) into bytes
- nconc (list #\? #\Space) into chars
- finally (return (list bytes
- (coerce chars 'string)))))
- (apply #'utf8-decode-tests
- (loop for i from first to last
- collect i into bytes
- collect #\? into chars
- finally (return (list bytes
- (coerce chars 'string)))))))
+ (apply #'utf8-decode-tests
+ (loop for i from first to last
+ nconc (list i 32) into bytes
+ nconc (list #\? #\Space) into chars
+ finally (return (list bytes
+ (coerce chars 'string)))))
+ (apply #'utf8-decode-tests
+ (loop for i from first to last
+ collect i into bytes
+ collect #\? into chars
+ finally (return (list bytes
+ (coerce chars 'string)))))))