source: trunk/source/tests/ansi-tests/formatter-c.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 3.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Dec  5 14:32:46 2004
4;;;; Contains: Tests of FORMATTER on the C directive
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10(deftest formatter.c.1
11  (let ((fn (formatter "~C")))
12    (loop
13     for c across +standard-chars+
14     when
15     (let* (n
16            (ignored (loop for i below (random 5) collect i))
17            (s (with-output-to-string (stream)
18                                      (setq n (multiple-value-list
19                                               (apply fn stream c ignored))))))
20       (unless (and (string= s (string c))
21                    (equal n (list ignored)))
22         (list s ignored n)))
23     collect it))
24  nil)
25
26(deftest formatter.c.1a
27  (let ((fn (formatter "~c")))
28    (loop
29     with count = 0
30     for i from 0 below (min #x10000 char-code-limit)
31     for c = (code-char i)
32     for ignored = (loop for j below (random 10) collect j)
33     when
34     (and c
35          (eql (char-code c) (char-int c))
36          (let* (n
37                 (s (with-output-to-string
38                      (stream)
39                      (setq n (multiple-value-list
40                               (apply fn stream c ignored))))))
41            (unless (and (string= s (string c))
42                         (equal n (list ignored)))
43              (incf count)
44              (list i c s ignored n))))
45     collect it
46     when (> count 100) collect "count limit exceeded" and do (loop-finish)))
47  nil)
48
49(deftest formatter.c.2
50  (let ((fn (formatter "~:C")))
51    (loop
52     for c across +standard-chars+
53     when
54     (and (graphic-char-p c)
55          (not (eql c #\Space))
56          (let* (n
57                 (ignored (loop for i below (random 5) collect i))
58                 (s (with-output-to-string (stream)
59                                           (setq n (multiple-value-list
60                                                    (apply fn stream c ignored))))))
61            (unless (and (string= s (string c))
62                         (equal n (list ignored)))
63              (list s ignored n))))
64     collect it))
65  nil)
66
67(deftest formatter.c.2a
68  (let ((fn (formatter "~:C")))
69    (loop
70     with count = 0
71     for i from 0 below (min #x10000 char-code-limit)
72     for c = (code-char i)
73     for ignored = (loop for j below (random 10) collect j)
74     when
75     (and c
76          (eql (char-code c) (char-int c))
77          (graphic-char-p c)
78          (not (eql c #\Space))
79          (let* (n
80                 (s (with-output-to-string
81                      (stream)
82                      (setq n (multiple-value-list
83                               (apply fn stream c ignored))))))
84            (unless (and (string= s (string c))
85                         (equal n (list ignored)))
86              (incf count)
87              (list i c s ignored n))))
88     collect it
89     when (> count 100) collect "count limit exceeded" and do (loop-finish)))
90  nil)
91
92(deftest formatter.c.4
93  (let ((fn (formatter "~:C"))
94        (n nil))
95    (loop for c across +standard-chars+
96          for s = (with-output-to-string
97                    (stream)
98                    (setq n (multiple-value-list (funcall fn stream c))))
99          unless (or (graphic-char-p c)
100                     (and (string= s (char-name c))
101                          (equal n '(nil))))
102          collect (list c (char-name c) s)))
103  nil)
104
105(deftest formatter.c.4a
106  (let ((fn (formatter "~:C"))
107        (n nil))
108    (loop for i from 0 below (min #x10000 char-code-limit)
109          for c = (code-char i)
110          for s = (and c
111                       (with-output-to-string
112                         (stream)
113                         (setq n (multiple-value-list (funcall fn stream c 5)))))
114          unless (or (not c)
115                     (graphic-char-p c)
116                     (and (string= s (char-name c))
117                          (equal n '((5)))))
118          collect (list c (char-name c) s)))
119  nil)
120
121(deftest formatter.c.5
122  (let ((fn (formatter "~@C"))
123        (n nil))
124    (loop for c across +standard-chars+
125          for s = (with-output-to-string
126                    (stream)
127                    (setq n (multiple-value-list (funcall fn stream c 1 2 3))))
128          for c2 = (read-from-string s)
129          unless (and (eql c c2)
130                      (equal n '((1 2 3))))
131          collect (list c s c2)))
132  nil)
133
134(deftest formatter.c.6
135  (let ((n nil)
136        (fn (formatter "~@:c")))
137    (loop for c across +standard-chars+
138          for s1 = (with-output-to-string
139                     (stream)
140                     (setf n (multiple-value-list (funcall fn stream c 1 2))))
141          for s2 = (format nil "~:@C" c)
142          unless (and (eql (search s1 s2) 0) (equal n '((1 2))))
143          collect (list c s1 s2 n)))
144  nil)
Note: See TracBrowser for help on using the repository browser.