source: trunk/source/tests/ansi-tests/string.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.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Mon Sep 30 19:16:59 2002
4;;;; Contains: Tests for string related functions and classes
5
6(in-package :cl-test)
7
8(deftest string.1
9  (subtypep* 'string 'array)
10  t t)
11
12(deftest string.2
13  (subtypep* 'string 'vector)
14  t t)
15
16(deftest string.3
17  (subtypep* 'string 'sequence)
18  t t)
19
20(deftest string.4
21  (let ((s (string #\a)))
22    (values (notnot (stringp s)) s))
23  t "a")
24
25(deftest string.5
26  (let ((s (string "")))
27    (values (notnot (stringp s)) s))
28  t "")
29
30(deftest string.6
31  (let ((s (string '|FOO|)))
32    (values (notnot (stringp s)) s))
33  t "FOO")
34
35(deftest string.7
36  (check-predicate
37   #'(lambda (x)
38       (handler-case (stringp (string x))
39                     (type-error () :caught))))
40  nil)
41
42(deftest string.8
43  :notes (:allow-nil-arrays :nil-vectors-are-strings)
44  (subtypep* '(array nil (*)) 'string)
45  t t)
46
47(deftest string.9
48  :notes (:allow-nil-arrays :nil-vectors-are-strings)
49  (subtypep* '(array nil 1) 'string)
50  t t)
51
52(deftest string.10
53  :notes (:allow-nil-arrays :nil-vectors-are-strings)
54  (string (make-array '(0) :element-type nil))
55  "")
56
57(deftest string.11
58  (typep* "abcd" 'string)
59  t)
60
61(deftest string.12
62  :notes (:allow-nil-arrays :nil-vectors-are-strings)
63  (typep* (make-array '(17) :element-type nil) 'string)
64  t)
65
66(deftest string.13
67  :notes (:allow-nil-arrays :nil-vectors-are-strings)
68  (typep* (make-array '(0) :element-type nil) 'string)
69  t)
70
71(deftest string.14
72  (let ((count 0))
73    (loop for i below (min char-code-limit 65536)
74          for c = (code-char i)
75          for s = (and c (string c))
76          when (and c
77                    (or (not (stringp s))
78                        (not (= (length s) 1))
79                        (not (eql c (char s 0)))))
80          collect (progn (incf count) (list i c s))
81          until (>= count 100)))
82  nil)
83
84(deftest string.15
85  (when (> char-code-limit 65536)
86    (loop for i = (random char-code-limit)
87          for c = (code-char i)
88          for s = (and c (string c))
89          repeat 2000
90          when (and c
91                    (or (not (stringp s))
92                        (not (= (length s) 1))
93                        (not (eql c (char s 0)))))
94          collect (list i c s)))
95  nil)
96
97(deftest string.16
98  (check-predicate #'(lambda (s) (or (not (stringp s)) (eq s (string s)))))
99  nil)
100
101(deftest string.17
102  (typep* "abc" '(string))
103  t)
104
105(deftest string.18
106  (typep* "abc" '(string *))
107  t)
108
109(deftest string.19
110  (typep* "abc" '(string 3))
111  t)
112
113(deftest string.20
114  (typep* "abc" '(string 2))
115  nil)
116
117(deftest string.21
118  (typep* "abc" '(string 4))
119  nil)
120
121(deftest string.22
122  (do-special-strings (s "X") (assert (typep s 'string)))
123  nil)
124                     
125(deftest string.23
126  (do-special-strings (s "X") (assert (typep s '(string))))
127  nil)
128                     
129(deftest string.24
130  (do-special-strings (s "X") (assert (typep s '(string *))))
131  nil)
132                     
133(deftest string.25
134  (do-special-strings (s "X")
135                      (or (array-has-fill-pointer-p s)
136                          (assert (typep s '(string 1)))))
137  nil)
138
139(deftest string.26
140  (let ((i 0))
141    (values (string (progn (incf i) "")) i))
142  "" 1)
143
144(def-fold-test string.fold.1 (string #\A))
145
146;;; Error tests
147
148(deftest string.error.1
149  (signals-error (string) program-error)
150  t)
151
152(deftest string.error.2
153  (signals-error (string nil nil) program-error)
154  t)
Note: See TracBrowser for help on using the repository browser.