source: trunk/source/tests/ansi-tests/print-characters.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.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Mar  5 07:12:20 2004
4;;;; Contains: Tests for printing of characters
5
6(in-package :cl-test)
7
8(compile-and-load "printer-aux.lsp")
9
10;;; See CLtS section 22.1.3.2, "Printing Characters"
11
12(deftest print.char.1
13  (with-standard-io-syntax
14    (loop for c across +standard-chars+
15          unless (equal (string c)
16                        (with-output-to-string (s)
17                          (princ c s)))
18          collect c))
19  nil)
20
21(deftest print.char.2
22  (with-standard-io-syntax
23    (loop for c across +code-chars+
24          unless (equal (string c)
25                        (with-output-to-string (s)
26                          (princ c s)))
27          collect c))
28  nil)
29
30(deftest print.char.3
31  (with-standard-io-syntax
32    (let ((*print-readably* nil))
33      (loop for c across +base-chars+
34            unless (or (eql c #\Space)
35                       (equal (format nil "#\\~C" c)
36                              (with-output-to-string (s)
37                                (prin1 c s))))
38            collect c)))
39  nil)
40
41(deftest print.char.4
42  (with-standard-io-syntax
43    (let ((*print-readably* nil))
44      (with-output-to-string (s)
45        (prin1 #\Space s))))
46  "#\\ ")
47
48(deftest print.char.5
49  (with-standard-io-syntax
50    (let ((*print-readably* nil))
51      (with-output-to-string (s)
52        (prin1 #\Newline s))))
53  "#\\Newline")
54
55(deftest print.char.6
56  (with-standard-io-syntax
57    (let ((*print-readably* nil))
58      (with-output-to-string (s)
59        (princ #\Newline s))))
60  #.(string #\Newline))
61
62(deftest print.char.7
63  (with-standard-io-syntax
64   (let ((*print-readably* nil))
65     (loop for c across +code-chars+
66           for str = (with-output-to-string (s) (prin1 c s))
67           for len = (length str)
68           unless (and (>= len 3)
69                       (equal (subseq str 0 2) "#\\")
70                       (or (= len 3)
71                           (let ((name (subseq str 2)))
72                             (eql c (name-char name)))))
73           collect c)))
74  nil)
75
76(deftest print.char.8
77  (loop for i = (random (min char-code-limit (ash 1 16)))
78        for c = (code-char i)
79        repeat 1000
80        unless (null c)
81        nconc (let ((result (randomly-check-readability c)))
82                (and result (list (cons i (first result))))))
83  nil)
84
85(deftest print.char.9
86  (loop for i = (random (min char-code-limit (ash 1 32)))
87        for c = (code-char i)
88        repeat 1000
89        unless (null c)
90        nconc (let ((result (randomly-check-readability c)))
91                (and result (list (cons i (first result))))))
92  nil)
93
94(deftest print.char.10
95  (with-standard-io-syntax
96   (let ((*print-readably* nil))
97     (loop for c across +standard-chars+
98           for str = (with-output-to-string (s) (prin1 c s))
99           unless (or (eql c #\Newline)
100                      (equal str (concatenate 'string "#\\" (string c))))
101           collect (list c str))))
102  nil)
103
104(deftest print.char.11
105  (with-standard-io-syntax
106   (let ((*print-readably* nil))
107     (let ((names '("Newline" "Tab" "Rubout" "Linefeed" "Page"
108                    "Backspace" "Return")))
109       (loop for name in names
110             for c = (name-char name)
111             for str = (with-output-to-string (s) (prin1 c s))
112             unless (or (null c)
113                        (and (>= (length str) 3)
114                             (equal (subseq str 0 2) "#\\")
115                             (member (subseq str 2) names
116                                     :test #'equal)))
117             collect (list c str)))))
118  nil)
Note: See TracBrowser for help on using the repository browser.