formatter-c.lsp 4.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Dec  5 14:32:46 2004
;;;; Contains: Tests of FORMATTER on the C directive

(in-package :cl-test)

(compile-and-load "printer-aux.lsp")

(deftest formatter.c.1
  (let ((fn (formatter "~C")))
    (loop
     for c across +standard-chars+
     when
     (let* (n
sds's avatar
sds committed
16 17 18 19
            (ignored (loop for i below (random 5) collect i))
            (s (with-output-to-string (stream)
                                      (setq n (multiple-value-list
                                               (apply fn stream c ignored))))))
20
       (unless (and (string= s (string c))
sds's avatar
sds committed
21 22
                    (equal n (list ignored)))
         (list s ignored n)))
23 24 25 26 27 28 29 30 31 32 33 34
     collect it))
  nil)

(deftest formatter.c.1a
  (let ((fn (formatter "~c")))
    (loop
     with count = 0
     for i from 0 below (min #x10000 char-code-limit)
     for c = (code-char i)
     for ignored = (loop for j below (random 10) collect j)
     when
     (and c
sds's avatar
sds committed
35 36 37 38 39 40 41 42 43 44
          (eql (char-code c) (char-int c))
          (let* (n
                 (s (with-output-to-string
                      (stream)
                      (setq n (multiple-value-list
                               (apply fn stream c ignored))))))
            (unless (and (string= s (string c))
                         (equal n (list ignored)))
              (incf count)
              (list i c s ignored n))))
45 46 47 48 49 50 51 52 53 54
     collect it
     when (> count 100) collect "count limit exceeded" and do (loop-finish)))
  nil)

(deftest formatter.c.2
  (let ((fn (formatter "~:C")))
    (loop
     for c across +standard-chars+
     when
     (and (graphic-char-p c)
sds's avatar
sds committed
55 56 57 58 59 60 61 62 63
          (not (eql c #\Space))
          (let* (n
                 (ignored (loop for i below (random 5) collect i))
                 (s (with-output-to-string (stream)
                                           (setq n (multiple-value-list
                                                    (apply fn stream c ignored))))))
            (unless (and (string= s (string c))
                         (equal n (list ignored)))
              (list s ignored n))))
64 65
     collect it))
  nil)
pfdietz's avatar
pfdietz committed
66 67

(deftest formatter.c.2a
68 69 70 71 72 73 74 75
  (let ((fn (formatter "~:C")))
    (loop
     with count = 0
     for i from 0 below (min #x10000 char-code-limit)
     for c = (code-char i)
     for ignored = (loop for j below (random 10) collect j)
     when
     (and c
sds's avatar
sds committed
76 77 78 79 80 81 82 83 84 85 86 87
          (eql (char-code c) (char-int c))
          (graphic-char-p c)
          (not (eql c #\Space))
          (let* (n
                 (s (with-output-to-string
                      (stream)
                      (setq n (multiple-value-list
                               (apply fn stream c ignored))))))
            (unless (and (string= s (string c))
                         (equal n (list ignored)))
              (incf count)
              (list i c s ignored n))))
88 89 90 91 92 93
     collect it
     when (> count 100) collect "count limit exceeded" and do (loop-finish)))
  nil)

(deftest formatter.c.4
  (let ((fn (formatter "~:C"))
sds's avatar
sds committed
94
        (n nil))
95
    (loop for c across +standard-chars+
sds's avatar
sds committed
96 97 98 99 100 101 102
          for s = (with-output-to-string
                    (stream)
                    (setq n (multiple-value-list (funcall fn stream c))))
          unless (or (graphic-char-p c)
                     (and (string= s (char-name c))
                          (equal n '(nil))))
          collect (list c (char-name c) s)))
103 104 105 106
  nil)

(deftest formatter.c.4a
  (let ((fn (formatter "~:C"))
sds's avatar
sds committed
107
        (n nil))
108
    (loop for i from 0 below (min #x10000 char-code-limit)
sds's avatar
sds committed
109 110 111 112 113 114 115 116 117 118
          for c = (code-char i)
          for s = (and c
                       (with-output-to-string
                         (stream)
                         (setq n (multiple-value-list (funcall fn stream c 5)))))
          unless (or (not c)
                     (graphic-char-p c)
                     (and (string= s (char-name c))
                          (equal n '((5)))))
          collect (list c (char-name c) s)))
119 120 121 122
  nil)

(deftest formatter.c.5
  (let ((fn (formatter "~@C"))
sds's avatar
sds committed
123
        (n nil))
124
    (loop for c across +standard-chars+
sds's avatar
sds committed
125 126 127 128 129 130 131
          for s = (with-output-to-string
                    (stream)
                    (setq n (multiple-value-list (funcall fn stream c 1 2 3))))
          for c2 = (read-from-string s)
          unless (and (eql c c2)
                      (equal n '((1 2 3))))
          collect (list c s c2)))
132 133 134 135
  nil)

(deftest formatter.c.6
  (let ((n nil)
sds's avatar
sds committed
136
        (fn (formatter "~@:c")))
137
    (loop for c across +standard-chars+
sds's avatar
sds committed
138 139 140 141 142 143
          for s1 = (with-output-to-string
                     (stream)
                     (setf n (multiple-value-list (funcall fn stream c 1 2))))
          for s2 = (format nil "~:@C" c)
          unless (and (eql (search s1 s2) 0) (equal n '((1 2))))
          collect (list c s1 s2 n)))
144
  nil)