X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fprint.impure.lisp;h=c773e76e17453c4de959bf8b59ddb7b108eefe28;hb=4fa1c71c7dfa5c6d361304321cc67069a6410694;hp=c6b23e9b91a3014353c5949bbf579176daeae4cb;hpb=d6d76c98535bddabd73c6338f8393b6e698f297f;p=sbcl.git diff --git a/tests/print.impure.lisp b/tests/print.impure.lisp index c6b23e9..c773e76 100644 --- a/tests/print.impure.lisp +++ b/tests/print.impure.lisp @@ -382,4 +382,123 @@ (prin1 table)))) print-not-readable))) +;; 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? (eval '(formatter "~>")) sb-format:format-error)) +(assert (raises-error? (eval '(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))))) + +;;; an off-by-one error in the ~R format directive until 1.0.15.20 +;;; prevented printing cardinals and ordinals between (expt 10 63) and +;;; (1- (expt 10 66)) +(assert (string= (format nil "~R" (expt 10 63)) "one vigintillion")) +(assert (string= (format nil "~:R" (expt 10 63)) "one vigintillionth")) + +;;; too-clever cacheing for PRINT-OBJECT resulted in a bogus method +;;; for printing RESTART objects. Check also CONTROL-STACK-EXHAUSTED +;;; and HEAP-EXHAUSTED-ERROR. +(let ((result (with-output-to-string (*standard-output*) + (princ (find-restart 'abort))))) + (assert (string/= result "#<" :end1 2))) +(let ((result (with-output-to-string (*standard-output*) + (princ (make-condition 'sb-kernel::control-stack-exhausted))))) + (assert (string/= result "#<" :end1 2))) +(let ((result (with-output-to-string (*standard-output*) + (princ (make-condition 'sb-kernel::heap-exhausted-error))))) + (assert (string/= result "#<" :end1 2))) + +(with-test (:name (:with-standard-io-syntax :bind-print-pprint-dispatch)) + (let ((*print-pprint-dispatch* (copy-pprint-dispatch nil))) + (set-pprint-dispatch 'symbol #'(lambda (stream obj) + (declare (ignore obj)) + (write-string "FOO" stream))) + (with-standard-io-syntax + (let ((*print-pretty* t)) + (assert (string= (princ-to-string 'bar) "BAR")))))) + +;;; bug-lp#488979 + +(defclass a-class-name () ()) + +(assert (find #\Newline + (let ((*print-pretty* t) + (*print-right-margin* 10)) + (format nil "~A" (make-instance 'a-class-name))) + :test #'char=)) + +(assert (not (find #\Newline + (let ((*print-pretty* nil) + (*print-right-margin* 10)) + (format nil "~A" (make-instance 'a-class-name))) + :test #'char=))) + +;;; The PRINT-OBJECT method for RANDOM-STATE used to have a bogus +;;; dimension argument for MAKE-ARRAY. +(with-test (:name :print-random-state) + (assert (equalp *random-state* + (read-from-string + (write-to-string *random-state*))))) + +(with-test (:name :write-return-value) + (assert (= 123 (funcall (compile nil (lambda () + (write 123))))))) + +(with-test (:name :write/write-to-string-compiler-macro-lp/598374+581564) + (let ((test (compile nil + `(lambda (object &optional output-stream) + (write object + :stream output-stream))))) + (assert (equal "(HELLO WORLD)" + (with-output-to-string (*standard-output*) + (let ((list '(hello world))) + (assert (eq list (funcall test list))))))) + (assert (equal "12" + (with-output-to-string (*standard-output*) + (assert (eql 12 (funcall test 12))))))) + (let ((test (compile nil + `(lambda () + (let ((*print-length* 42)) + (write-to-string *print-length* :length nil)))))) + (assert (equal "42" (funcall test))))) + ;;; success