Commit 8803098d authored by pfdietz's avatar pfdietz
Browse files

Many new printer tests, including tests of parts of format.

parent f67527e2
......@@ -90,3 +90,6 @@ Got: 0
a collection of random test harnesses.
27. Be sure the various string operations work on non-simple strings.
28. Add tests for reading/printing with packages with weird names (lower case letters,
digits, etc.)
......@@ -944,6 +944,3 @@ the condition to go uncaught if it cannot be classified."
(*read-suppress* nil)
(*readtable* (copy-readtable nil)))
,@body))
\ No newline at end of file
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Mon Aug 2 01:42:35 2004
;;;; Contains: Tests of printing using the ~A directive
(in-package :cl-test)
(deftest format.a.1
(with-standard-io-syntax
(format nil "~a" nil))
"NIL")
(deftest format.a.2
(with-standard-io-syntax
(let ((*print-case* :downcase))
(format nil "~A" nil)))
"nil")
(deftest format.a.3
(with-standard-io-syntax
(let ((*print-case* :capitalize))
(format nil "~a" nil)))
"Nil")
(deftest format.a.4
(format nil "~:a" nil)
"()")
(deftest format.a.5
(with-standard-io-syntax
(format nil "~:A" '(nil)))
"(NIL)")
(deftest format.a.6
(with-standard-io-syntax
(format nil "~:A" #(nil)))
"#(NIL)")
(deftest format.a.7
(loop for c across +standard-chars+
for s1 = (string c)
for s2 = (format nil "~a" s1)
unless (string= s1 s2)
collect (list c s1 s2))
nil)
(deftest format.a.8
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s1 = (and c (string c))
for s2 = (and c (format nil "~A" s1))
unless (or (null c) (string= s1 s2))
do (incf count) and collect (list c s1 s2)
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
(deftest format.a.9
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s1 = (format nil "~~~d@a" i)
for s2 = (format nil s1 nil)
collect s2)))
"NIL"
"NIL"
"NIL"
" NIL"
" NIL"
" NIL"
" NIL"
" NIL"
" NIL"
" NIL")
(deftest format.a.10
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s1 = (format nil "~~~da" i)
for s2 = (format nil s1 nil)
collect s2)))
"NIL"
"NIL"
"NIL"
"NIL "
"NIL "
"NIL "
"NIL "
"NIL "
"NIL "
"NIL ")
(deftest format.a.11
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s1 = (format nil "~~~d@:A" i)
for s2 = (format nil s1 nil)
collect s2)))
"()"
"()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()")
(deftest format.a.12
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s1 = (format nil "~~~d:a" i)
for s2 = (format nil s1 nil)
collect s2)))
"()"
"()"
"() "
"() "
"() "
"() "
"() "
"() "
"() "
"() ")
(deftest format.a.13
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s2 = (format nil "~v:A" i nil)
collect s2)))
"()"
"()"
"() "
"() "
"() "
"() "
"() "
"() "
"() "
"() ")
(deftest format.a.14
(with-standard-io-syntax
(apply
#'values
(loop for i from 1 to 10
for s2 = (format nil "~v:@a" i nil)
collect s2)))
"()"
"()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()"
" ()")
(deftest format.a.15
(with-standard-io-syntax
(format nil "~vA" nil nil))
"NIL")
(deftest format.a.16
(with-standard-io-syntax
(format nil "~v:A" nil nil))
"()")
(deftest format.a.17
(with-standard-io-syntax
(format nil "~@A" nil))
"NIL")
(deftest format.a.18
(with-standard-io-syntax
(format nil "~v@A" nil nil))
"NIL")
(deftest format.a.19
(with-standard-io-syntax
(format nil "~v:@a" nil nil))
"()")
(deftest format.a.20
(with-standard-io-syntax
(format nil "~v@:a" nil nil))
"()")
;;; With colinc specified
(deftest format.a.21
(format nil "~3,1a" nil)
"NIL")
(deftest format.a.22
(format nil "~4,3a" nil)
"NIL ")
(deftest format.a.23
(format nil "~3,3@a" nil)
"NIL")
(deftest format.a.24
(format nil "~4,4@a" nil)
" NIL")
(deftest format.a.25
(format nil "~5,3@a" nil)
" NIL")
(deftest format.a.26
(format nil "~5,3A" nil)
"NIL ")
(deftest format.a.27
(format nil "~7,3@a" nil)
" NIL")
(deftest format.a.28
(format nil "~7,3A" nil)
"NIL ")
;;; With minpad
(deftest format.a.29
(loop for i from -4 to 10
collect (format nil "~v,,2A" i "ABC"))
("ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "))
(deftest format.a.30
(format nil "~3,,+2A" "ABC")
"ABC ")
(deftest format.a.31
(format nil "~3,,0A" "ABC")
"ABC")
(deftest format.a.32
(format nil "~3,,-1A" "ABC")
"ABC")
(deftest format.a.33
(format nil "~3,,0A" "ABCD")
"ABCD")
(deftest format.a.34
(format nil "~3,,-1A" "ABCD")
"ABCD")
;;; With padchar
(deftest format.a.35
(format nil "~4,,,'XA" "AB")
"ABXX")
(deftest format.a.36
(format nil "~4,,,a" "AB")
"AB ")
(deftest format.a.37
(format nil "~4,,,'X@a" "AB")
"XXAB")
(deftest format.a.38
(format nil "~4,,,@A" "AB")
" AB")
(deftest format.a.39
(format nil "~10,,,vA" nil "abcde")
"abcde ")
(deftest format.a.40
(format nil "~10,,,v@A" nil "abcde")
" abcde")
(deftest format.a.41
(format nil "~10,,,va" #\* "abcde")
"abcde*****")
(deftest format.a.42
(format nil "~10,,,v@a" #\* "abcde")
"*****abcde")
;;; Other tests
(deftest format.a.43
(format nil "~3,,vA" nil "ABC")
"ABC")
(deftest format.a.44
(loop for i from 0 to 6
collect (format nil "~3,,vA" i "ABC"))
("ABC"
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "
"ABC "))
(deftest format.a.44a
(loop for i from 0 to 6
collect (format nil "~3,,v@A" i "ABC"))
("ABC"
" ABC"
" ABC"
" ABC"
" ABC"
" ABC"
" ABC"))
(deftest format.a.45
(format nil "~4,,va" -1 "abcd")
"abcd")
(deftest format.a.46
(format nil "~5,vA" nil "abc")
"abc ")
(deftest format.a.47
(format nil "~5,vA" 3 "abc")
"abc ")
(deftest format.a.48
(format nil "~5,v@A" 3 "abc")
" abc")
;;; # parameters
(deftest format.a.49
(format nil "~#A" "abc" nil nil nil)
"abc ")
(deftest format.a.50
(format nil "~#@a" "abc" nil nil nil nil nil)
" abc")
(deftest format.a.51
(format nil "~5,#a" "abc" nil nil nil)
"abc ")
(deftest format.a.52
(format nil "~5,#@A" "abc" nil nil nil)
" abc")
(deftest format.a.53
(format nil "~4,#A" "abc" nil nil)
"abc ")
(deftest format.a.54
(format nil "~4,#@A" "abc" nil nil)
" abc")
(deftest format.a.55
(format nil "~#,#A" "abc" nil nil nil)
"abc ")
(deftest format.a.56
(format nil "~#,#@A" "abc" nil nil nil)
" abc")
(deftest format.a.57
(format nil "~-100A" "xyz")
"xyz")
(deftest format.a.58
(format nil "~-100000000000000000000a" "xyz")
"xyz")
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Jul 27 23:52:20 2004
;;;; Contains: Tests of format with ~& directive
(in-package :cl-test)
(deftest format.&.1
(format nil "~0&")
"")
(deftest format.&.2
(format nil "~&")
"")
(deftest format.&.3
(format nil "X~&")
"X
")
(deftest format.&.4
(format nil "X~%~&")
"X
")
(deftest format.&.5
(loop for i from 1 to 100
for s1 = (make-string (1- i) :initial-element #\Newline)
for s2 = (format nil (format nil "~~~D&" i))
unless (string= s1 s2)
collect i)
nil)
(deftest format.&.6
(loop for i from 1 to 100
for s1 = (concatenate 'string
"X"
(make-string i :initial-element #\Newline))
for s2 = (format nil (format nil "X~~~D&" i))
unless (string= s1 s2)
collect i)
nil)
(deftest format.&.7
(format nil "~v&" nil)
"")
(deftest format.&.8
(format nil "X~v&" nil)
"X
")
(deftest format.&.9
(loop for i from 1 to 100
for s1 = (make-string (1- i) :initial-element #\Newline)
for s2 = (format nil "~V&" i)
unless (string= s1 s2)
collect i)
nil)
(deftest format.&.10
(loop for i from 1 to (min (- call-arguments-limit 3) 100)
for s1 = (make-string (1- i) :initial-element #\Newline)
for args = (make-list i)
for s2 = (apply #'format nil "~#&" args)
unless (string= s1 s2)
collect i)
nil)
(deftest format.&.11
(format nil "X~V%" 0)
"X")
(deftest format.&.12
(format nil "X~#%")
"X")
(deftest format.&.13
(format nil "X~#%" 'a 'b 'c)
"X
")
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Aug 1 05:10:10 2004
;;;; Contains: Tests of the ~B format directive
(in-package :cl-test)
(compile-and-load "printer-aux.lsp")
(deftest format.b.1
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for i = (- (random (+ x x)) x)
for s1 = (format nil "~B" i)
for j = (let ((*read-base* 2)) (read-from-string s1))
repeat 1000
when (or (/= i j)
(find #\+ s1)
(loop for c across s1 thereis (not (find c "-01"))))
collect (list i s1 j)))
nil)
(deftest format.b.2
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for i = (- (random (+ x x)) x)
for s1 = (format nil "~@b" i)
for j = (let ((*read-base* 2)) (read-from-string s1))
repeat 1000
when (or (/= i j)
(loop for c across s1 thereis (not (find c "-+01"))))
collect (list i s1 j)))
nil)
(deftest format.b.3
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for mincol = (random 30)
for i = (- (random (+ x x)) x)
for s1 = (format nil "~b" i)
for s2 = (format nil (format nil "~~~db" mincol) i)
for pos = (search s1 s2)
repeat 1000
when (or (null pos)
(and (> mincol (length s1))
(or (/= (length s2) mincol)
(not (eql (position #\Space s2 :test-not #'eql)
(- (length s2) (length s1)))))))
collect (list i mincol s1 s2 pos)))
nil)
(deftest format.b.4
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for mincol = (random 30)
for i = (- (random (+ x x)) x)
for s1 = (format nil "~@B" i)
for s2 = (format nil (format nil "~~~d@b" mincol) i)
for pos = (search s1 s2)
repeat 1000
when (or (null pos)
(and (>= i 0) (not (eql (elt s1 0) #\+)))
(and (> mincol (length s1))
(or (/= (length s2) mincol)
(not (eql (position #\Space s2 :test-not #'eql)
(- (length s2) (length s1)))))))
collect (list i mincol s1 s2 pos)))
nil)
(deftest format.b.5
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for mincol = (random 30)
for padchar = (random-from-seq +standard-chars+)
for i = (- (random (+ x x)) x)
for s1 = (format nil "~b" i)
for s2 = (format nil (format nil "~~~d,'~c~c" mincol padchar
(random-from-seq "bB"))
i)
for pos = (search s1 s2)
repeat 1000
when (or (null pos)
(and (> mincol (length s1))
(or (/= (length s2) mincol)
(find padchar s2 :end (- (length s2) (length s1))
:test-not #'eql))))
collect (list i mincol s1 s2 pos)))
nil)
(deftest format.b.6
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for mincol = (random 30)
for padchar = (random-from-seq +standard-chars+)
for i = (- (random (+ x x)) x)
for s1 = (format nil "~b" i)
for s2 = (format nil "~v,vb" mincol padchar i)
for pos = (search s1 s2)
repeat 1000
when (or (null pos)
(and (> mincol (length s1))
(or (/= (length s2) mincol)
(find padchar s2 :end (- (length s2) (length s1))
:test-not #'eql))))
collect (list i mincol s1 s2 pos)))
nil)
(deftest format.b.7
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for mincol = (random 30)
for padchar = (random-from-seq +standard-chars+)
for i = (- (random (+ x x)) x)
for s1 = (format nil "~@B" i)
for s2 = (format nil "~v,v@b" mincol padchar i)
for pos = (search s1 s2)
repeat 1000
when (or (null pos)
(and (>= i 0) (not (eql (elt s1 0) #\+)))
(and (> mincol (length s1))
(or (/= (length s2) mincol)
(find padchar s2 :end (- (length s2) (length s1))
:test-not #'eql))))
collect (list i mincol s1 s2 pos)))
nil)
;;; Comma tests
(deftest format.b.8
(loop for i from -7 to 7
for s1 = (format nil "~b" i)
for s2 = (format nil "~:b" i)
unless (string= s1 s2)
collect (list i s1 s2))
nil)
(deftest format.b.9
(with-standard-io-syntax
(loop for x = (ash 1 (+ 2 (random 80)))
for i = (- (random (+ x x)) x)
for commachar = #\,
for s1 = (format nil "~b" i)
for s2 = (format nil "~:B" i)
repeat 1000
unless (and (string= s1 (remove commachar s2))
(not (eql (elt s2 0) commachar))
(or (>= i 0) (not (eql (elt s2 1) commachar)))
(let ((len (length s2))