X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fprint.impure.lisp;h=2198269a4029dea2bbba7801da443bdd15123f58;hb=ad3beba970fab6e451a461c9f9b14faf4ef17718;hp=e3184bc5af9ed0119d60b7e4e1ce35d7223a9171;hpb=5c0190fbca4852096b30b4ed53394e762b9e6cd4;p=sbcl.git diff --git a/tests/print.impure.lisp b/tests/print.impure.lisp index e3184bc..2198269 100644 --- a/tests/print.impure.lisp +++ b/tests/print.impure.lisp @@ -247,5 +247,95 @@ (assert (string= (princ-to-string #\7) (write-to-string #\7 :escape nil :readably nil)))) +;;; in FORMAT, ~^ inside ~:{ should go to the next case, not break +;;; iteration, even if one argument is just a one-element list. +(assert (string= (format nil "~:{~A~^~}" '((A) (C D))) "AC")) + +;;; errors should be raised if pprint and justification are mixed +;;; injudiciously... +(dolist (x (list "~<~:;~>~_" "~<~:;~>~I" "~<~:;~>~W" + "~<~:;~>~:T" "~<~:;~>~<~:>" "~_~<~:;~>" + "~I~<~:;~>" "~W~<~:;~>" "~:T~<~:;~>" "~<~:>~<~:;~>")) + (assert (raises-error? (format nil x nil))) + (assert (raises-error? (format nil (eval `(formatter ,x)) nil)))) +;;; ...but not in judicious cases. +(dolist (x (list "~<~;~>~_" "~<~;~>~I" "~<~;~>~W" + "~<~;~>~:T" "~<~;~>~<~>" "~_~<~;~>" + "~I~<~;~>" "~W~<~;~>" "~:T~<~;~>" "~<~>~<~;~>" + "~<~:;~>~T" "~T~<~:;~>")) + (assert (format nil x nil)) + (assert (format nil (eval `(formatter ,x)) nil))) + +;;; bug 350: bignum printing so memory-hungry that heap runs out +;;; -- just don't stall here forever on a slow box +(handler-case + (with-timeout 10 + (print (ash 1 1000000))) + (timeout () + (print 'timeout!))) + +;;; bug 371: bignum print/read inconsistency +(defvar *bug-371* -7043009959286724629649270926654940933664689003233793014518979272497911394287216967075767325693021717277238746020477538876750544587281879084559996466844417586093291189295867052594478662802691926547232838591510540917276694295393715934079679531035912244103731582711556740654671309980075069010778644542022/670550434139267031632063192770201289106737062379324644110801846820471752716238484923370056920388400273070254958650831435834503195629325418985020030706879602898158806736813101434594805676212779217311897830937606064579213895527844045511878668289820732425014254579493444623868748969110751636786165152601) +(let ((*print-base* 5) + (*read-base* 5) + (*print-radix* nil)) + (assert (= *bug-371* (read-from-string (prin1-to-string *bug-371*))))) + +;;; a spot of random-testing for rational printing +(defvar *seed-state* (make-random-state)) +(print *seed-state*) ; so that we can reproduce errors +(let ((seed (make-random-state *seed-state*))) + (loop repeat 42 + do (let ((n (random (ash 1 1000) seed)) + (d (random (ash 1 1000) seed))) + (when (zerop (random 2 seed)) + (setf n (- n))) + (let ((r (/ n d))) + (loop for base from 2 to 36 + do (let ((*print-base* base) + (*read-base* base) + (*print-radix* nil)) + (assert (= r (read-from-string (prin1-to-string r)))) + (if (= 36 base) + (decf *read-base*) + (incf *read-base*)) + (assert (not (eql r (read-from-string (prin1-to-string r))))) + (let ((*print-radix* t)) + (assert (= r (read-from-string + (princ-to-string r))))))))) + (write-char #\.) + (finish-output))) + +;;;; Bugs, found by PFD +;;; NIL parameter for ~^ means `not supplied' +(loop for (format arg result) in + '(("~:{~D~v^~D~}" ((3 1 4) (1 0 2) (7 nil) (5 nil 6)) "341756") + ("~:{~1,2,v^~A~}" ((nil 0) (3 1) (0 2)) "02")) + do (assert (string= (funcall #'format nil format arg) result)) + do (assert (string= (with-output-to-string (s) + (funcall (eval `(formatter ,format)) s arg)) + result))) + +;;; NIL first parameter for ~R is equivalent to no parameter. +(assert (string= (format nil "~VR" nil 5) "five")) +(assert (string= (format nil (formatter "~VR") nil 6) "six")) + +;;; CSR inserted a bug into Burger & Dybvig's float printer. Caught +;;; by Raymond Toy +(assert (string= (format nil "~E" 1d23) "1.0d+23")) + +;;; Fixed-format bugs from CLISP's test suite (reported by Bruno +;;; Haible, bug 317) +(assert (string= (format nil "~1F" 10) "10.")) +(assert (string= (format nil "~0F" 10) "10.")) +(assert (string= (format nil "~2F" 1234567.1) "1234567.")) + +;;; here's one that seems to fail most places. I think this is right, +;;; and most of the other answers I've seen are definitely wrong. +(assert (string= (format nil "~G" 1d23) "100000000000000000000000. ")) + +;;; Adam Warner's test case +(assert (string= (format nil "~@F" 1.23) "+1.23")) + ;;; success (quit :unix-status 104)