+;; Test that we can print characters readably regardless of the external format
+;; of the stream.
+
+(defun test-readable-character (character external-format)
+ (let ((file "print.impure.tmp"))
+ (unwind-protect
+ (progn
+ (with-open-file (stream file
+ :direction :output
+ :external-format external-format
+ :if-exists :supersede)
+ (write character :stream stream :readably t))
+ (with-open-file (stream file
+ :direction :input
+ :external-format external-format
+ :if-does-not-exist :error)
+ (assert (char= (read stream) character))))
+ (ignore-errors
+ (delete-file file)))))
+
+#+sb-unicode
+(with-test (:name (:print-readable :character :utf-8))
+ (test-readable-character (code-char #xfffe) :utf-8))
+
+#+sb-unicode
+(with-test (:name (:print-readable :character :iso-8859-1))
+ (test-readable-character (code-char #xfffe) :iso-8859-1))
+
+(assert (string= (eval '(format nil "~:C" #\a)) "a"))
+(assert (string= (format nil (formatter "~:C") #\a) "a"))
+
+;;; This used to trigger an AVER instead.
+(assert (raises-error? (format t "~>") sb-format:format-error))
+
+;;; readably printing hash-tables, check for circularity
+(let ((x (cons 1 2))
+ (h (make-hash-table))
+ (*print-readably* t)
+ (*print-circle* t)
+ (*read-eval* t))
+ (setf (gethash x h) h)
+ (destructuring-bind (x2 . h2) (read-from-string (write-to-string (cons x h)))
+ (assert (equal x x2))
+ (assert (eq h2 (gethash x2 h2)))))
+