copy-seq.lsp 4.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Nov  2 21:38:08 2002
;;;; Contains: Tests for COPY-SEQ

(in-package :cl-test)

;;; This function is extensively used elsewhere, but is tested again
;;; here for completeness.

(deftest copy-seq.1
  (copy-seq nil)
  nil)

(deftest copy-seq.2
  (let* ((s1 '(a b c))
17
	 (s2 (check-values (copy-seq s1))))
18
19
20
21
22
23
    (and (not (eql s1 s2))
	 (equalt s1 s2)))
  t)

(deftest copy-seq.3
  (let* ((s1 #(a b c))
24
	 (s2 (check-values (copy-seq s1))))
25
26
27
28
29
30
    (and (not (eql s1 s2)) s2))
  #(a b c))

(deftest copy-seq.4
  (let* ((s1 (make-array '(4) :initial-contents '(a b c d)
			 :adjustable t))
31
	 (s2 (check-values (copy-seq s1))))
32
33
34
35
36
37
38
39
40
    (and (not (eql s1 s2))
	 (simple-vector-p s2)
	 s2))
  #(a b c d))


(deftest copy-seq.5
  (let* ((s1 (make-array '(4) :initial-contents '(a b c d)
			 :fill-pointer 3))
41
	 (s2 (check-values (copy-seq s1))))
42
43
44
45
46
47
48
49
50
    (and (not (eql s1 s2))
	 (simple-vector-p s2)
	 s2))
  #(a b c))

(deftest copy-seq.6
  (let* ((a1 (make-array '(6) :initial-contents '(a b c d e f)))
	 (a2 (make-array '(4) :displaced-to a1
			 :displaced-index-offset 1))
51
	 (s2 (check-values (copy-seq a2))))
52
53
54
55
56
57
58
59
60
61
    (and (not (eql a2 s2))
	 (simple-vector-p s2)
	 s2))
  #(b c d e))

(deftest copy-seq.7
  (let* ((s1 (make-array '(4)
			 :element-type 'base-char
			 :initial-contents '(#\a #\b #\c #\d)
			 :adjustable t))
62
	 (s2 (check-values (copy-seq s1))))
63
64
65
66
67
68
69
70
71
72
73
    (and (not (eql s1 s2))
	 (simple-string-p s2)
	 s2))
  "abcd")


(deftest copy-seq.8
  (let* ((s1 (make-array '(4)
			 :element-type 'base-char
			 :initial-contents '(#\a #\b #\c #\d)
			 :fill-pointer 3))
74
	 (s2 (check-values (copy-seq s1))))
75
76
77
78
79
80
81
82
83
84
85
    (and (not (eql s1 s2))
	 (simple-string-p s2)
	 s2))
  "abc")

(deftest copy-seq.9
  (let* ((a1 (make-array '(6) :initial-contents '(#\a #\b #\c #\d #\e #\f)
			 :element-type 'base-char))
	 (a2 (make-array '(4) :displaced-to a1
			 :element-type 'base-char
			 :displaced-index-offset 1))
86
	 (s2 (check-values (copy-seq a2))))
87
88
89
90
91
92
93
    (and (not (eql a2 s2))
	 (simple-string-p s2)
	 s2))
  "bcde")

(deftest copy-seq.10
  (let*((s1 "abcd")
94
	(s2 (check-values (copy-seq s1))))
95
96
97
98
99
100
    (and (not (eql s1 s2))
	 s2))
  "abcd")

(deftest copy-seq.11
  (let* ((s1 #*0010110)
101
	 (s2 (check-values (copy-seq s1))))
102
103
104
105
106
107
108
109
110
    (and (not (eql s1 s2))
	 (simple-bit-vector-p s2)
	 s2))
  #*0010110)

(deftest copy-seq.12
  (let* ((s1 (make-array '(4) :initial-contents '(0 0 1 0)
			 :element-type 'bit
			 :adjustable t))
111
	 (s2 (check-values (copy-seq s1))))
112
113
114
115
116
117
118
119
120
    (and (not (eql s1 s2))
	 (simple-bit-vector-p s2)
	 s2))
  #*0010)

(deftest copy-seq.13
  (let* ((s1 (make-array '(4) :initial-contents '(0 0 1 0)
			 :element-type 'bit
			 :fill-pointer 3))
121
	 (s2 (check-values (copy-seq s1))))
122
123
124
125
126
127
128
129
130
131
132
    (and (not (eql s1 s2))
	 (simple-bit-vector-p s2)
	 s2))
  #*001)

(deftest copy-seq.14
  (let* ((a1 (make-array '(6) :initial-contents '(0 0 1 0 1 1)
			 :element-type 'bit))
	 (a2 (make-array '(4) :displaced-to a1
			 :displaced-index-offset 1
			 :element-type 'bit))
133
	 (s2 (check-values (copy-seq a2))))
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    (and (not (eql a2 s2))
	 (simple-bit-vector-p s2)
	 s2))
  #*0101)

(deftest copy-seq.15
  (copy-seq "")
  "")

(deftest copy-seq.16
  (copy-seq #*)
  #*)

(deftest copy-seq.17
  (copy-seq #())
  #())

151
152
(deftest copy-seq.18
  (let* ((x (make-array '(10) :initial-contents '(a b c d e f g h i j)))
153
	 (y (check-values (copy-seq x))))
154
155
156
    (equal-array x y))
  t)

157
(deftest copy-seq.19
158
  :notes (:nil-vectors-are-strings)
159
160
161
  (copy-seq (make-array '(0) :element-type nil))
  "")

162
163
164
165
166
(deftest copy-seq.order.1
  (let ((i 0))
    (values (copy-seq (progn (incf i) "abc")) i))
  "abc" 1)

167
168
169
170
171
172
173
174
175
176
177
178
179
;;; Error tests

(deftest copy-seq.error.1
  (classify-error (copy-seq 10))
  type-error)

(deftest copy-seq.error.2
  (classify-error (copy-seq 'a))
  type-error)

(deftest copy-seq.error.3
  (classify-error (copy-seq 13.21))
  type-error)
180
181
182
183
184
185
186
187

(deftest copy-seq.error.4
  (classify-error (copy-seq))
  program-error)

(deftest copy-seq.error.5
  (classify-error (copy-seq "abc" 2 nil))
  program-error)
188
189
190
191
192

(deftest copy-seq.error.6
  (classify-error (locally (copy-seq 10) t))
  type-error)