sbcl.sbcl/tests/pprint.pure.lisp
Christophe Rhodes 6d5bd93403 Track significant whitespace in pretty streams
When we emit `#\ ` for a Space character to a pretty stream, note in
the pretty stream that the trailing space is significant, so that
outputting a line with that text at the end does not delete that
trailing space.

SB-PRETTY:NOTE-SIGNIFICANT-SPACE is defined and exported (from an
internals package) in order to be the answer to "how can user-defined
pretty printing routines do this?"

Fixes lp#1985814
2023-08-11 14:29:44 +01:00

41 lines
1.7 KiB
Common Lisp

;;;; test of the pretty-printer
;;;; 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.
(with-test (:name :pprint-logical-block-#=nil)
(assert (not (search "#1=" (write-to-string '(let () (let () x))
:circle t
:pretty t)))))
(with-test (:name :pprint-list-spaces)
(let* ((list (make-list 50 :initial-element #\Space))
(string (write-to-string list :pretty t :escape t)))
(assert (equal (read-from-string string) list))
(assert (= (count #\Newline string) 2))))
(with-test (:name :pprint-vector-spaces)
(let* ((vector (coerce (make-list 50 :initial-element #\Space) 'vector))
(string (write-to-string vector :pretty t :escape t)))
(assert (equalp (read-from-string string) vector))
(assert (= (count #\Newline string) 2))))
(with-test (:name :pprint-random-spaces)
(dotimes (i 100)
(let* ((list (loop repeat 1000 if (= (random 2) 1) collect #\Space else collect #\Tab))
(lstring (write-to-string list :pretty t :escape t))
(lread (read-from-string lstring))
(vector (coerce list 'vector))
(vstring (write-to-string vector :pretty t :escape t))
(vread (read-from-string vstring)))
(assert (equal list lread))
(assert (equalp vector vread)))))