Commit 8803098d authored by pfdietz's avatar pfdietz

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
")
This diff is collapsed.
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Jul 27 23:07:16 2004
;;;; Contains: Tests of formatted output, ~C directive
(in-package :cl-test)
(compile-and-load "printer-aux.lsp")
;;; Test of the ~C directive
(deftest format.c.1
(loop for c across +standard-chars+
for s = (format nil "~C" c)
unless (string= s (string c))
collect (list c s))
nil)
(deftest format.c.1a
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s = (and c (format nil "~c" c))
unless (or (not c)
(not (eql (char-code c) (char-int c)))
(string= s (string c)))
do (incf count) and collect (list i c s)
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
(deftest format.c.2
(loop for c across +standard-chars+
for s = (format nil "~:c" c)
unless (or (not (graphic-char-p c))
(eql c #\Space)
(string= s (string c)))
collect (list c s))
nil)
(deftest format.c.2a
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s = (and c (format nil "~:C" c))
unless (or (not c)
(not (eql (char-code c) (char-int c)))
(not (graphic-char-p c))
(eql c #\Space)
(string= s (string c)))
do (incf count) and collect (list i c s)
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
(deftest format.c.3
(format nil "~:C" #\Space)
#.(char-name #\Space))
(deftest format.c.4
(loop for c across +standard-chars+
for s = (format nil "~:C" c)
unless (or (graphic-char-p c)
(string= s (char-name c)))
collect (list c (char-name c) s))
nil)
(deftest format.c.4a
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s = (and c (format nil "~:c" c))
unless (or (not c)
(not (eql (char-code c) (char-int c)))
(graphic-char-p c)
(string= s (char-name c)))
do (incf count) and collect (print (list i c s))
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
(deftest format.c.5
(loop for c across +standard-chars+
for s = (format nil "~@c" c)
for c2 = (read-from-string s)
unless (eql c c2)
collect (list c s c2))
nil)
(deftest format.c.5a
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s = (and c (format nil "~@C" c))
for c2 = (and c (read-from-string s))
unless (eql c c2)
do (incf count) and collect (list c s c2)
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
(deftest format.c.6
(loop for c across +standard-chars+
for s1 = (format nil "~:C" c)
for s2 = (format nil "~:@C" c)
unless (eql (search s1 s2) 0)
collect (list c s1 s2))
nil)
(deftest format.c.6a
(loop with count = 0
for i from 0 below (min #x10000 char-code-limit)
for c = (code-char i)
for s1 = (and c (format nil "~:C" c))
for s2 = (and c (format nil "~@:C" c))
unless (or (not c) (eql (search s1 s2) 0))
do (incf count) and collect (list c s1 s2)
when (> count 100) collect "count limit exceeded" and do (loop-finish))
nil)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Wed Jul 28 00:20:46 2004
;;;; Contains: Tests of format with ~| directive
(in-package :cl-test)
(deftest format.page.1
(format nil "~0|")
"")
(deftest format.page.2
(let ((s (format nil "~|")))
(cond
((string= s "") nil)
((> (length s) 1) (values s :too-long))
(t
(let ((c (elt s 0)))
(loop for i from 2 to 100
for s = (format nil (format nil "~~~D|" i))
unless (and (= (length s) i)
(every #'(lambda (c2) (char= c c2)) s))
collect i)))))
nil)
(deftest format.page.3
(let ((s (format nil "~|")))
(cond
((string= s "") nil)
((> (length s) 1) (values s :too-long))
(t
(let ((c (elt s 0)))
(loop for i from 2 to 100
for s = (format nil "~v|" i)
unless (and (= (length s) i)
(every #'(lambda (c2) (char= c c2)) s))
collect i)))))
nil)
(deftest format.page.4
(format nil "~V|" 0)
"")
(deftest format.page.5
(string=t (format nil "~v|" nil)
(format nil "~|"))
t)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Jul 27 23:47:44 2004
;;;; Contains: Tests of format with ~% directive
(in-package :cl-test)
(deftest format.%.1
(format nil "~%")
#.(string #\Newline))
(deftest format.%.2
(loop for i from 0 to 100
for s1 = (make-string i :initial-element #\Newline)
for s2 = (format nil (format nil "~~~D%" i))
unless (string= s1 s2)
collect i)
nil)
(deftest format.%.3
(format nil "~v%" nil)
"
")
(deftest format.%.4
(format nil "~V%" 1)
#.(string #\Newline))
(deftest format.%.5
(loop for i from 0 to 100
for s1 = (make-string i :initial-element #\Newline)
for s2 = (format nil "~v%" i)
unless (string= s1 s2)
collect i)
nil)
(deftest format.%.6
(loop for i from 0 to (min (- call-arguments-limit 3) 100)
for args = (make-list i)
for s1 = (make-string i :initial-element #\Newline)
for s2 = (apply #'format nil "~#%" args)
unless (string= s1 s2)
collect i)
nil)
This diff is collapsed.
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Aug 3 11:55:07 2004
;;;; Contains: Test of the ~S format directive
(in-package :cl-test)
(deftest format.s.1
(let ((*print-readably* nil)
(*print-case* :upcase))
(format nil "~s" nil))
"NIL")
(deftest format.s.2
(let ((*print-readably* nil))
(format nil "~:s" nil))
"()")
(deftest format.s.3
(let ((*print-readably* nil)
(*print-case* :upcase))
(format nil "~:s" '(nil)))
"(NIL)")
(deftest format.s.4
(let ((*print-readably* nil)
(*print-case* :downcase))
(format nil "~s" 'nil))
"nil")
(deftest format.s.5
(let ((*print-readably* nil)
(*print-case* :capitalize))
(format nil "~s" 'nil))
"Nil")
(deftest format.s.6
(with-standard-io-syntax
(let ((*print-readably* nil))
(format nil "~:s" #(nil))))
"#(NIL)")
(deftest format.s.7
(with-standard-io-syntax
(let ((*print-readably* nil))
(loop for c across +standard-chars+
for s = (format nil "~S" c)
for c2 = (read-from-string s)
unless (eql c c2)
collect (list c s c2))))