format-p.lsp 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- 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")

10 11
(def-format-test format.p.1
  "~p" (1) "")
12

13 14
(def-format-test format.p.2
  "~P" (2) "s")
15

16 17
(def-format-test format.p.3
  "~p" (0) "s")
18

19 20
(def-format-test format.p.4
  "~P" (1.0) "s")
21 22 23

(deftest format.p.5
  (loop for x in *universe*
sds's avatar
sds committed
24 25 26
        for s = (format nil "~p" x)
        unless (or (eql x 1) (string= s "s"))
        collect (list x s))
27 28
  nil)

pfdietz's avatar
pfdietz committed
29 30 31
(deftest formatter.p.5
  (let ((fn (formatter "~p")))
    (loop for x in *universe*
sds's avatar
sds committed
32 33 34
          for s = (formatter-call-to-string fn x)
          unless (or (eql x 1) (string= s "s"))
          collect (list x s)))
pfdietz's avatar
pfdietz committed
35 36
  nil)

37 38
;;; :p

39 40
(def-format-test format.p.6
  "~D cat~:P" (1) "1 cat")
41

42 43
(def-format-test format.p.7
  "~D cat~:p" (2) "2 cats")
44

45 46
(def-format-test format.p.8
  "~D cat~:P" (0) "0 cats")
47

48 49
(def-format-test format.p.9
  "~D cat~:p" ("No") "No cats")
50 51 52

;;; :@p

53 54
(def-format-test format.p.10
  "~D penn~:@P" (1) "1 penny")
55

56 57
(def-format-test format.p.11
  "~D penn~:@p" (2) "2 pennies")
58

59 60
(def-format-test format.p.12
  "~D penn~@:P" (0) "0 pennies")
61

62 63
(def-format-test format.p.13
  "~D penn~@:p" ("No") "No pennies")
64 65 66

;;; @p

67 68
(def-format-test format.p.14
  "~@p" (1) "y")
69

70 71
(def-format-test format.p.15
  "~@P" (2) "ies")
72

73 74
(def-format-test format.p.16
  "~@p" (0) "ies")
75

76 77
(def-format-test format.p.17
  "~@P" (1.0) "ies")
78 79 80

(deftest format.p.18
  (loop for x in *universe*
sds's avatar
sds committed
81 82 83
        for s = (format nil "~@p" x)
        unless (or (eql x 1) (string= s "ies"))
        collect (list x s))
84
  nil)
pfdietz's avatar
pfdietz committed
85 86 87 88

(deftest formatter.p.18
  (let ((fn (formatter "~@P")))
    (loop for x in *universe*
sds's avatar
sds committed
89 90 91
          for s = (formatter-call-to-string fn x)
          unless (or (eql x 1) (string= s "ies"))
          collect (list x s)))
pfdietz's avatar
pfdietz committed
92
  nil)