Commit 0d785f3f authored by pfdietz's avatar pfdietz

Add tests for ~?, ~(, and ~P format directives

parent 2235522e
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Oct 17 21:32:45 2004
;;;; Contains: Tests of the ~P format directives
(in-package :cl-test)
(compile-and-load "printer-aux.lsp")
(deftest format.p.1
(format nil "~p" 1)
"")
(deftest format.p.2
(format nil "~P" 2)
"s")
(deftest format.p.3
(format nil "~p" 0)
"s")
(deftest format.p.4
(format nil "~P" 1.0)
"s")
(deftest format.p.5
(loop for x in *universe*
for s = (format nil "~p" x)
unless (or (eql x 1) (string= s "s"))
collect (list x s))
nil)
;;; :p
(deftest format.p.6
(format nil "~D cat~:P" 1)
"1 cat")
(deftest format.p.7
(format nil "~D cat~:p" 2)
"2 cats")
(deftest format.p.8
(format nil "~D cat~:P" 0)
"0 cats")
(deftest format.p.9
(format nil "~D cat~:p" "No")
"No cats")
;;; :@p
(deftest format.p.10
(format nil "~D penn~:@P" 1)
"1 penny")
(deftest format.p.11
(format nil "~D penn~:@p" 2)
"2 pennies")
(deftest format.p.12
(format nil "~D penn~@:P" 0)
"0 pennies")
(deftest format.p.13
(format nil "~D penn~@:p" "No")
"No pennies")
;;; @p
(deftest format.p.14
(format nil "~@p" 1)
"y")
(deftest format.p.15
(format nil "~@P" 2)
"ies")
(deftest format.p.16
(format nil "~@p" 0)
"ies")
(deftest format.p.17
(format nil "~@P" 1.0)
"ies")
(deftest format.p.18
(loop for x in *universe*
for s = (format nil "~@p" x)
unless (or (eql x 1) (string= s "ies"))
collect (list x s))
nil)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Oct 17 20:28:24 2004
;;;; Contains: Tests of the ~( format directives
(in-package :cl-test)
(compile-and-load "printer-aux.lsp")
(deftest format.paren.1
(format nil "~(XXyy~AuuVV~)" "ABc dEF ghI")
"xxyyabc def ghiuuvv")
;;; Conversion of simple characters to downcase
(deftest format.paren.2
(loop for i from 0 below (min char-code-limit (ash 1 16))
for c = (code-char i)
when (and c
(eql (char-code c) (char-int c))
(upper-case-p c)
(let ((s1 (format nil "~(~c~)" c))
(s2 (string (char-downcase c))))
(if
(or (not (eql (length s1) 1))
(not (eql (length s2) 1))
(not (eql (elt s1 0)
(elt s2 0))))
(list i c s1 s2)
nil)))
collect it)
nil)
(deftest format.paren.3
(format nil "~@(this is a TEST.~)")
"This is a test.")
(deftest format.paren.4
(format nil "~@(!@#$%^&*this is a TEST.~)")
"!@#$%^&*This is a test.")
(deftest format.paren.5
(format nil "~:(this is a TEST.~)")
"This Is A Test.")
(deftest format.paren.6
(format nil "~:(this is7a TEST.~)")
"This Is7a Test.")
(deftest format.paren.7
(format nil "~:@(this is AlSo A teSt~)")
"THIS IS ALSO A TEST")
(deftest format.paren.8
(loop for i from 0 below (min char-code-limit (ash 1 16))
for c = (code-char i)
when (and c
(eql (char-code c) (char-int c))
(lower-case-p c)
(let ((s1 (format nil "~@:(~c~)" c))
(s2 (string (char-upcase c))))
(if
(or (not (eql (length s1) 1))
(not (eql (length s2) 1))
(not (eql (elt s1 0)
(elt s2 0))))
(list i c s1 s2)
nil)))
collect it)
nil)
;;; Nested conversion
(deftest format.paren.9
(format nil "~(aBc ~:(def~) GHi~)")
"abc def ghi")
(deftest format.paren.10
(format nil "~(aBc ~(def~) GHi~)")
"abc def ghi")
(deftest format.paren.11
(format nil "~@(aBc ~:(def~) GHi~)")
"Abc def ghi")
(deftest format.paren.12
(format nil "~(aBc ~@(def~) GHi~)")
"abc def ghi")
(deftest format.paren.13
(format nil "~(aBc ~:(def~) GHi~)")
"abc def ghi")
(deftest format.paren.14
(format nil "~:(aBc ~(def~) GHi~)")
"Abc Def Ghi")
(deftest format.paren.15
(format nil "~:(aBc ~:(def~) GHi~)")
"Abc Def Ghi")
(deftest format.paren.16
(format nil "~:(aBc ~@(def~) GHi~)")
"Abc Def Ghi")
(deftest format.paren.17
(format nil "~:(aBc ~@:(def~) GHi~)")
"Abc Def Ghi")
(deftest format.paren.18
(format nil "~@(aBc ~(def~) GHi~)")
"Abc def ghi")
(deftest format.paren.19
(format nil "~@(aBc ~:(def~) GHi~)")
"Abc def ghi")
(deftest format.paren.20
(format nil "~@(aBc ~@(def~) GHi~)")
"Abc def ghi")
(deftest format.paren.21
(format nil "~@(aBc ~@:(def~) GHi~)")
"Abc def ghi")
(deftest format.paren.22
(format nil "~:@(aBc ~(def~) GHi~)")
"ABC DEF GHI")
(deftest format.paren.23
(format nil "~@:(aBc ~:(def~) GHi~)")
"ABC DEF GHI")
(deftest format.paren.24
(format nil "~:@(aBc ~@(def~) GHi~)")
"ABC DEF GHI")
(deftest format.paren.25
(format nil "~@:(aBc ~@:(def~) GHi~)")
"ABC DEF GHI")
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Oct 17 20:08:18 2004
;;;; Contains: Tests of the ~? and ~@? format directives
(in-package :cl-test)
(compile-and-load "printer-aux.lsp")
(deftest format.?.1
(format nil "~?" "" nil)
"")
(deftest format.?.2
(format nil "~?" "~A" '(1))
"1")
(deftest format.?.3
(format nil "~?" "" '(1))
"")
(deftest format.?.4
(format nil "~? ~A" "" '(1) 2)
" 2")
(deftest format.?.5
(format nil "a~?z" "b~?y" '("c~?x" ("~A" (1))))
"abc1xyz")
;;; Tests of ~@?
(deftest format.@?.1
(format nil "~@?" "")
"")
(deftest format.@?.2
(format nil "~@?" "~A" 1)
"1")
(deftest format.@?.3
(format nil "~@? ~A" "<~A>" 1 2)
"<1> 2")
(deftest format.@?.4
(format nil "a~@?z" "b~@?y" "c~@?x" "~A" 1)
"abc1xyz")
(deftest format.@?.5
(format nil "~{~A~@?~A~}" '(1 "~4*" 2 3 4 5 6))
"16")
......@@ -42,3 +42,8 @@
(load "format-goto.lsp")
(load "format-conditional.lsp")
(load "format-brace.lsp")
(load "format-question.lsp")
;;; 22.3.8
(load "format-paren.lsp")
(load "format-p.lsp")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment