format-c.lsp 3.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jul 27 23:07:16 2004
;;;; Contains: Tests of formatted output, ~C directive

(in-package :cl-test)

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

;;; Test of the ~C directive

(deftest format.c.1
  (loop for c across +standard-chars+
sds's avatar
sds committed
14 15 16
        for s = (format nil "~C" c)
        unless (string= s (string c))
        collect (list c s))
17 18 19 20
  nil)

(deftest format.c.1a
  (loop with count = 0
sds's avatar
sds committed
21 22 23 24 25 26 27 28
        for i from 0 below (min #x10000 char-code-limit)
        for c = (code-char i)
        for s = (and c (format nil "~c" c))
        unless (or (not c)
                   (not (eql (char-code c) (char-int c)))
                   (string= s (string c)))
        do (incf count) and collect (list i c s)
        when (> count 100) collect "count limit exceeded" and do (loop-finish))
29 30 31 32
  nil)

(deftest format.c.2
  (loop for c across +standard-chars+
sds's avatar
sds committed
33 34 35 36 37
        for s = (format nil "~:c" c)
        unless (or (not (graphic-char-p c))
                   (eql c #\Space)
                   (string= s (string c)))
        collect (list c s))
38 39 40 41
  nil)

(deftest format.c.2a
  (loop with count = 0
sds's avatar
sds committed
42 43 44 45 46 47 48 49 50 51
        for i from 0 below (min #x10000 char-code-limit)
        for c = (code-char i)
        for s = (and c (format nil "~:C" c))
        unless (or (not c)
                   (not (eql (char-code c) (char-int c)))
                   (not (graphic-char-p c))
                   (eql c #\Space)
                   (string= s (string c)))
        do (incf count) and collect (list i c s)
        when (> count 100) collect "count limit exceeded" and do (loop-finish))
52 53
  nil)

54 55
(def-format-test format.c.3
  "~:C" (#\Space) #.(char-name #\Space))
56 57 58

(deftest format.c.4
  (loop for c across +standard-chars+
sds's avatar
sds committed
59 60 61 62
        for s = (format nil "~:C" c)
        unless (or (graphic-char-p c)
                   (string= s (char-name c)))
        collect (list c (char-name c) s))
63 64 65 66
  nil)

(deftest format.c.4a
  (loop with count = 0
sds's avatar
sds committed
67 68 69 70 71 72 73 74 75
        for i from 0 below (min #x10000 char-code-limit)
        for c = (code-char i)
        for s = (and c (format nil "~:c" c))
        unless (or (not c)
                   (not (eql (char-code c) (char-int c)))
                   (graphic-char-p c)
                   (string= s (char-name c)))
        do (incf count) and collect (print (list i c s))
        when (> count 100) collect "count limit exceeded" and do (loop-finish))
76 77 78 79
  nil)

(deftest format.c.5
  (loop for c across +standard-chars+
sds's avatar
sds committed
80 81 82 83
        for s = (format nil "~@c" c)
        for c2 = (read-from-string s)
        unless (eql c c2)
        collect (list c s c2))
84 85 86 87
  nil)

(deftest format.c.5a
  (loop with count = 0
sds's avatar
sds committed
88 89 90 91 92 93 94
        for i from 0 below (min #x10000 char-code-limit)
        for c = (code-char i)
        for s = (and c (format nil "~@C" c))
        for c2 = (and c (read-from-string s))
        unless (eql c c2)
        do (incf count) and collect (list c s c2)
        when (> count 100) collect "count limit exceeded" and do (loop-finish))
95 96 97 98
  nil)

(deftest format.c.6
  (loop for c across +standard-chars+
sds's avatar
sds committed
99 100 101 102
        for s1 = (format nil "~:C" c)
        for s2 = (format nil "~:@C" c)
        unless (eql (search s1 s2) 0)
        collect (list c s1 s2))
103 104 105 106
  nil)

(deftest format.c.6a
  (loop with count = 0
sds's avatar
sds committed
107 108 109 110 111 112 113
        for i from 0 below (min #x10000 char-code-limit)
        for c = (code-char i)
        for s1 = (and c (format nil "~:C" c))
        for s2 = (and c (format nil "~@:C" c))
        unless (or (not c) (eql (search s1 s2) 0))
        do (incf count) and collect (list c s1 s2)
        when (> count 100) collect "count limit exceeded" and do (loop-finish))
114 115 116 117
  nil)