0.8.0.66:
[sbcl.git] / tests / print.impure.lisp
index d9fa69e..725b1da 100644 (file)
@@ -1,6 +1,18 @@
-(in-package :cl-user)
+;;;; miscellaneous tests of printing stuff
+
+;;;; This software is part of the SBCL system. See the README file for
+;;;; more information.
+;;;;
+;;;; While most of SBCL is derived from the CMU CL system, the test
+;;;; files (like this one) were written from scratch after the fork
+;;;; from CMU CL.
+;;;; 
+;;;; This software is in the public domain and is provided with
+;;;; absolutely no warranty. See the COPYING and CREDITS files for
+;;;; more information.
 
 (load "assertoid.lisp")
+(use-package "ASSERTOID")
 
 ;;; We should be able to output X readably (at least when *READ-EVAL*).
 (defun assert-readable-output (x)
 
 ;;; This was a bug in SBCL until 0.6.12.40 (originally reported as a
 ;;; CMU CL bug by Erik Naggum on comp.lang.lisp).
-(loop for *print-base* from 2 to 36
+(loop for base from 2 to 36
       with *print-radix* = t
-      do
-      (assert (string= "#*101" (format nil "~S" #*101))))
+      do (let ((*print-base* base))
+          (assert (string= "#*101" (format nil "~S" #*101)))))
 
 ;;; bug in sbcl-0.7.1.25, reported by DB sbcl-devel 2002-02-25
 (assert (string= "0.5" (format nil "~2D" 0.5)))
 (assert (string= (format nil "~/cl-user:print-foo:print-foo/" 2) "2"))
 (assert (string= (format nil "~/cl-user::print-foo:print-foo/" 2) "2"))
 
+;;; Check for error detection of illegal directives in a~<..~> justify
+;;; block (see ANSI section 22.3.5.2)
+(assert (raises-error? (format nil "~<~W~>" 'foo)))
+(assert (raises-error? (format nil "~<~<~A~:>~>" '(foo))))
+(assert (string= (format nil "~<~<~A~>~>" 'foo) "FOO"))
+
+;;; Check that arrays that we print while *PRINT-READABLY* is true are
+;;; in fact generating similar objects.
+(assert (equal (array-dimensions
+               (read-from-string
+                (with-output-to-string (s)
+                  (let ((*print-readably* t))
+                    (print (make-array '(1 2 0)) s)))))
+              '(1 2 0)))
+
+(assert (multiple-value-bind (result error)
+           (ignore-errors (read-from-string
+                           (with-output-to-string (s)
+                             (let ((*print-readably* t))
+                               (print (make-array '(1 0 1)) s)))))
+         ;; it might not be readably-printable
+         (or (typep error 'print-not-readable)
+             ;; or else it had better have the same dimensions
+             (equal (array-dimensions result) '(1 0 1)))))
+
+;;; before 0.8.0.66 it signalled UNBOUND-VARIABLE
+(write #(1 2 3) :pretty nil :readably t)
+
 ;;; success
 (quit :unix-status 104)