source: trunk/source/tests/ansi-tests/replace.lsp @ 8991

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

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

File size: 16.7 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Aug 27 16:11:38 2002
4;;;; Contains: Tests for REPLACE
5
6(in-package :cl-test)
7
8(deftest replace-list.1
9  (let* ((x (copy-seq '(a b c d e f g)))
10         (result (replace x '(x y z))))
11    (values (eqt x result) result))
12  t
13  (x y z d e f g))
14
15(deftest replace-list.2
16  (let* ((x (copy-seq '(a b c d e f g)))
17         (result (replace x '(x y z) :start1 1)))
18    (values (eqt x result) result))
19  t
20  (a x y z e f g))
21
22(deftest replace-list.3
23  (let* ((x (copy-seq '(a b c d e f g)))
24         (result (replace x '(x y z) :start1 4)))
25    (values (eqt x result) result))
26  t
27  (a b c d x y z))
28
29(deftest replace-list.4
30  (let* ((x (copy-seq '(a b c d e f g)))
31         (result (replace x '(x y z) :start1 5)))
32    (values (eqt x result) result))
33  t
34  (a b c d e x y))
35
36(deftest replace-list.5
37  (let* ((x (copy-seq '(a b c d e f g)))
38         (result (replace x '(x y z) :start1 6)))
39    (values (eqt x result) result))
40  t
41  (a b c d e f x))
42
43(deftest replace-list.6
44  (let* ((x (copy-seq '(a b c d e f g)))
45         (result (replace x #(x y z) :start1 2)))
46    (values (eqt x result) result))
47  t
48  (a b x y z f g))
49
50(deftest replace-list.7
51  (replace nil #(x y z))
52  nil)
53
54(deftest replace-list.8
55  (let* ((x (copy-seq '(a b c d e f g)))
56         (result (replace x '(x y z) :end1 1)))
57    (values (eqt x result) result))
58  t
59  (x b c d e f g))
60
61(deftest replace-list.9
62  (let* ((x (copy-seq '(a b c d e f g)))
63         (result (replace x '(x y z) :start1 3 :end1 4)))
64    (values (eqt x result) result))
65  t
66  (a b c x e f g))
67
68(deftest replace-list.10
69  (let* ((x (copy-seq '(a b c d e f g)))
70         (result (replace x '(x y z) :start1 0 :end1 5)))
71    (values (eqt x result) result))
72  t
73  (x y z d e f g))
74
75
76(deftest replace-list.11
77  (let* ((x (copy-seq '(a b c d e f g)))
78         (result (replace x '(x y z) :start2 1)))
79    (values (eqt x result) result))
80  t
81  (y z c d e f g))
82
83(deftest replace-list.12
84  (let* ((x (copy-seq '(a b c d e f g)))
85         (result (replace x '(x y z) :start2 1 :end1 nil)))
86    (values (eqt x result) result))
87  t
88  (y z c d e f g))
89
90(deftest replace-list.13
91  (let* ((x (copy-seq '(a b c d e f g)))
92         (result (replace x '(x y z) :start2 1 :end2 nil)))
93    (values (eqt x result) result))
94  t
95  (y z c d e f g))
96
97(deftest replace-list.14
98  (let* ((x (copy-seq '(a b c d e f g)))
99         (result (replace x '(x y z) :start2 1 :end2 2)))
100    (values (eqt x result) result))
101  t
102  (y b c d e f g))
103
104(deftest replace-list.15
105  (let* ((x (copy-seq '(a b c d e f g)))
106         (result (replace x '(x y z) :start1 4 :end1 5 :start2 1 :end2 2)))
107    (values (eqt x result) result))
108  t
109  (a b c d y f g))
110
111(deftest replace-list.16
112  (let* ((x (copy-seq '(a b c d e f)))
113         (y #(1 2 3))
114         (result (replace x y :start1 1)))
115    (values (eqt x result) result))
116  t
117  (a 1 2 3 e f))
118
119(deftest replace-list.17
120  (let* ((x (copy-seq '(a b c d e f)))
121         (y (make-array '(3) :initial-contents '(1 2 3)
122                        :fill-pointer t))
123         (result (replace x y :start1 1)))
124    (values (eqt x result) result))
125  t
126  (a 1 2 3 e f))
127
128(deftest replace-list.18
129  (let* ((x (copy-seq '(a b c d e f)))
130         (y (make-array '(6) :initial-contents '(1 2 3 4 5 6)
131                        :fill-pointer 3))
132         (result (replace x y :start1 1)))
133    (values (eqt x result) result))
134  t
135  (a 1 2 3 e f))
136
137(deftest replace-list.19
138  (let* ((x (copy-seq '(a b c d e f)))
139         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
140    (values (eqt x result) result))
141  t
142  (b c d d e f))
143
144(deftest replace-list.20
145  (let* ((x (copy-seq '(a b c d e f)))
146         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
147    (values (eqt x result) result))
148  t
149  (a a b c e f))
150
151
152;;; Tests of vectors
153
154(deftest replace-vector.1
155  (let* ((x (copy-seq #(a b c d e f g)))
156         (result (replace x #(x y z))))
157    (values (eqt x result) result))
158  t
159  #(x y z d e f g))
160
161(deftest replace-vector.2
162  (let* ((x (copy-seq #(a b c d e f g)))
163         (result (replace x #(x y z) :start1 1)))
164    (values (eqt x result) result))
165  t
166  #(a x y z e f g))
167
168(deftest replace-vector.3
169  (let* ((x (copy-seq #(a b c d e f g)))
170         (result (replace x #(x y z) :start1 4)))
171    (values (eqt x result) result))
172  t
173  #(a b c d x y z))
174
175(deftest replace-vector.4
176  (let* ((x (copy-seq #(a b c d e f g)))
177         (result (replace x #(x y z) :start1 5)))
178    (values (eqt x result) result))
179  t
180  #(a b c d e x y))
181
182(deftest replace-vector.5
183  (let* ((x (copy-seq #(a b c d e f g)))
184         (result (replace x #(x y z) :start1 6)))
185    (values (eqt x result) result))
186  t
187  #(a b c d e f x))
188
189(deftest replace-vector.6
190  (let* ((x (copy-seq #(a b c d e f g)))
191         (result (replace x '(x y z) :start1 2)))
192    (values (eqt x result) result))
193  t
194  #(a b x y z f g))
195
196(deftest replace-vector.7
197  (replace #() #(x y z))
198  #())
199
200(deftest replace-vector.8
201  (let* ((x (copy-seq #(a b c d e f g)))
202         (result (replace x #(x y z) :end1 1)))
203    (values (eqt x result) result))
204  t
205  #(x b c d e f g))
206
207(deftest replace-vector.9
208  (let* ((x (copy-seq #(a b c d e f g)))
209         (result (replace x #(x y z) :start1 3 :end1 4)))
210    (values (eqt x result) result))
211  t
212  #(a b c x e f g))
213
214(deftest replace-vector.10
215  (let* ((x (copy-seq #(a b c d e f g)))
216         (result (replace x #(x y z) :start1 0 :end1 5)))
217    (values (eqt x result) result))
218  t
219  #(x y z d e f g))
220
221
222(deftest replace-vector.11
223  (let* ((x (copy-seq #(a b c d e f g)))
224         (result (replace x #(x y z) :start2 1)))
225    (values (eqt x result) result))
226  t
227  #(y z c d e f g))
228
229(deftest replace-vector.12
230  (let* ((x (copy-seq #(a b c d e f g)))
231         (result (replace x #(x y z) :start2 1 :end1 nil)))
232    (values (eqt x result) result))
233  t
234  #(y z c d e f g))
235
236(deftest replace-vector.13
237  (let* ((x (copy-seq #(a b c d e f g)))
238         (result (replace x #(x y z) :start2 1 :end2 nil)))
239    (values (eqt x result) result))
240  t
241  #(y z c d e f g))
242
243(deftest replace-vector.14
244  (let* ((x (copy-seq #(a b c d e f g)))
245         (result (replace x #(x y z) :start2 1 :end2 2)))
246    (values (eqt x result) result))
247  t
248  #(y b c d e f g))
249
250(deftest replace-vector.15
251  (let* ((x (copy-seq #(a b c d e f g)))
252         (result (replace x #(x y z) :start1 4 :end1 5 :start2 1 :end2 2)))
253    (values (eqt x result) result))
254  t
255  #(a b c d y f g))
256
257(deftest replace-vector.16
258  (let* ((x (copy-seq #(a b c d e f)))
259         (y '(1 2 3))
260         (result (replace x y :start1 1)))
261    (values (eqt x result) result))
262  t
263  #(a 1 2 3 e f))
264
265(deftest replace-vector.17
266  (let* ((x (copy-seq #(a b c d e f)))
267         (y (make-array '(3) :initial-contents '(1 2 3)
268                        :fill-pointer t))
269         (result (replace x y :start1 1)))
270    (values (eqt x result) result))
271  t
272  #(a 1 2 3 e f))
273
274(deftest replace-vector.18
275  (let* ((x (copy-seq #(a b c d e f)))
276         (y (make-array '(6) :initial-contents '(1 2 3 4 5 6)
277                        :fill-pointer 3))
278         (result (replace x y :start1 1)))
279    (values (eqt x result) result))
280  t
281  #(a 1 2 3 e f))
282
283(deftest replace-vector.19
284  (let* ((x (copy-seq #(a b c d e f)))
285         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
286    (values (eqt x result) result))
287  t
288  #(b c d d e f))
289
290(deftest replace-vector.21
291  (let* ((x (copy-seq #(a b c d e f)))
292         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
293    (values (eqt x result) result))
294  t
295  #(a a b c e f))
296
297;;; tests on bit vectors
298
299(deftest replace-bit-vector.1
300  (let* ((x (copy-seq #*1101001))
301         (result (replace x #*011)))
302    (values (eqt x result) result))
303  t
304  #*0111001)
305
306(deftest replace-bit-vector.2
307  (let* ((x (copy-seq #*1101001))
308         (result (replace x #*011 :start1 1)))
309    (values (eqt x result) result))
310  t
311  #*1011001)
312
313(deftest replace-bit-vector.3
314  (let* ((x (copy-seq #*1101001))
315         (result (replace x #*011 :start1 4)))
316    (values (eqt x result) result))
317  t
318  #*1101011)
319
320(deftest replace-bit-vector.4
321  (let* ((x (copy-seq #*0000000))
322         (result (replace x #*111 :start1 5)))
323    (values (eqt x result) result))
324  t
325  #*0000011)
326
327(deftest replace-bit-vector.5
328  (let* ((x (copy-seq #*0000000))
329         (result (replace x #*100 :start1 6)))
330    (values (eqt x result) result))
331  t
332  #*0000001)
333
334(deftest replace-bit-vector.6
335  (let* ((x (copy-seq #*0000000))
336         (result (replace x '(1 1 1) :start1 2)))
337    (values (eqt x result) result))
338  t
339  #*0011100)
340
341(deftest replace-bit-vector.7
342  (replace #* #*111)
343  #*)
344
345(deftest replace-bit-vector.8
346  (let* ((x (copy-seq #*0000000))
347         (result (replace x #*111 :end1 1)))
348    (values (eqt x result) result))
349  t
350  #*1000000)
351
352(deftest replace-bit-vector.9
353  (let* ((x (copy-seq #*0000000))
354         (result (replace x #*110 :start1 3 :end1 4)))
355    (values (eqt x result) result))
356  t
357  #*0001000)
358
359(deftest replace-bit-vector.10
360  (let* ((x (copy-seq #*0000000))
361         (result (replace x #*111 :start1 0 :end1 5)))
362    (values (eqt x result) result))
363  t
364  #*1110000)
365
366
367(deftest replace-bit-vector.11
368  (let* ((x (copy-seq #*0000000))
369         (result (replace x #*011 :start2 1)))
370    (values (eqt x result) result))
371  t
372  #*1100000)
373
374(deftest replace-bit-vector.12
375  (let* ((x (copy-seq #*0000000))
376         (result (replace x #*011 :start2 1 :end1 nil)))
377    (values (eqt x result) result))
378  t
379  #*1100000)
380
381(deftest replace-bit-vector.13
382  (let* ((x (copy-seq #*0000000))
383         (result (replace x #*011 :start2 1 :end2 nil)))
384    (values (eqt x result) result))
385  t
386  #*1100000)
387
388(deftest replace-bit-vector.14
389  (let* ((x (copy-seq #*0000000))
390         (result (replace x #*011 :start2 1 :end2 2)))
391    (values (eqt x result) result))
392  t
393  #*1000000)
394
395(deftest replace-bit-vector.15
396  (let* ((x (copy-seq #*0000000))
397         (result (replace x #*011 :start1 4 :end1 5 :start2 1 :end2 2)))
398    (values (eqt x result) result))
399  t
400  #*0000100)
401
402(deftest replace-bit-vector.16
403  (let* ((x (copy-seq #*001011))
404         (y '(1 0 1))
405         (result (replace x y :start1 1)))
406    (values (eqt x result) result))
407  t
408  #*010111)
409
410(deftest replace-bit-vector.17
411  (let* ((x (copy-seq #*001011))
412         (y (make-array '(3) :initial-contents '(1 0 1)
413                        :fill-pointer t :element-type 'bit))
414         (result (replace x y :start1 1)))
415    (values (eqt x result) result))
416  t
417  #*010111)
418
419(deftest replace-bit-vector.18
420  (let* ((x (copy-seq #*001011))
421         (y (make-array '(6) :initial-contents '(1 0 1 0 0 1)
422                        :fill-pointer 3
423                        :element-type 'bit))
424         (result (replace x y :start1 1)))
425    (values (eqt x result) result))
426  t
427  #*010111)
428
429(deftest replace-bit-vector.19
430  (let* ((x (copy-seq #*001011))
431         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
432    (values (eqt x result) result))
433  t
434  #*010011)
435
436(deftest replace-bit-vector.21
437  (let* ((x (copy-seq #*001011))
438         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
439    (values (eqt x result) result))
440  t
441  #*000111)
442
443;;; Tests on strings
444
445(deftest replace-string.1
446  (let* ((x (copy-seq "abcdefg"))
447         (result (replace x "xyz")))
448    (values (eqt x result) result))
449  t
450  "xyzdefg")
451
452(deftest replace-string.2
453  (let* ((x (copy-seq "abcdefg"))
454         (result (replace x "xyz" :start1 1)))
455    (values (eqt x result) result))
456  t
457  "axyzefg")
458
459(deftest replace-string.3
460  (let* ((x (copy-seq "abcdefg"))
461         (result (replace x "xyz" :start1 4)))
462    (values (eqt x result) result))
463  t
464  "abcdxyz")
465
466(deftest replace-string.4
467  (let* ((x (copy-seq "abcdefg"))
468         (result (replace x "xyz" :start1 5)))
469    (values (eqt x result) result))
470  t
471  "abcdexy")
472
473(deftest replace-string.5
474  (let* ((x (copy-seq "abcdefg"))
475         (result (replace x "xyz" :start1 6)))
476    (values (eqt x result) result))
477  t
478  "abcdefx")
479
480(deftest replace-string.6
481  (let* ((x (copy-seq "abcdefg"))
482         (result (replace x '(#\x #\y #\z) :start1 2)))
483    (values (eqt x result) result))
484  t
485  "abxyzfg")
486
487(deftest replace-string.7
488  (replace "" "xyz")
489  "")
490
491(deftest replace-string.8
492  (let* ((x (copy-seq "abcdefg"))
493         (result (replace x "xyz" :end1 1)))
494    (values (eqt x result) result))
495  t
496  "xbcdefg")
497
498(deftest replace-string.9
499  (let* ((x (copy-seq "abcdefg"))
500         (result (replace x "xyz" :start1 3 :end1 4)))
501    (values (eqt x result) result))
502  t
503  "abcxefg")
504
505(deftest replace-string.10
506  (let* ((x (copy-seq "abcdefg"))
507         (result (replace x "xyz" :start1 0 :end1 5)))
508    (values (eqt x result) result))
509  t
510  "xyzdefg")
511
512
513(deftest replace-string.11
514  (let* ((x (copy-seq "abcdefg"))
515         (result (replace x "xyz" :start2 1)))
516    (values (eqt x result) result))
517  t
518  "yzcdefg")
519
520(deftest replace-string.12
521  (let* ((x (copy-seq "abcdefg"))
522         (result (replace x "xyz" :start2 1 :end1 nil)))
523    (values (eqt x result) result))
524  t
525  "yzcdefg")
526
527(deftest replace-string.13
528  (let* ((x (copy-seq "abcdefg"))
529         (result (replace x "xyz" :start2 1 :end2 nil)))
530    (values (eqt x result) result))
531  t
532  "yzcdefg")
533
534(deftest replace-string.14
535  (let* ((x (copy-seq "abcdefg"))
536         (result (replace x "xyz" :start2 1 :end2 2)))
537    (values (eqt x result) result))
538  t
539  "ybcdefg")
540
541(deftest replace-string.15
542  (let* ((x (copy-seq "abcdefg"))
543         (result (replace x "xyz" :start1 4 :end1 5 :start2 1 :end2 2)))
544    (values (eqt x result) result))
545  t
546  "abcdyfg")
547
548(deftest replace-string.16
549  (let* ((x (copy-seq "abcdef"))
550         (y (coerce "123" 'list))
551         (result (replace x y :start1 1)))
552    (values (eqt x result) result))
553  t
554  "a123ef")
555
556(deftest replace-string.17
557  (let* ((x (copy-seq "abcdef"))
558         (y (make-array '(3) :initial-contents '(#\1 #\2 #\3)
559                        :fill-pointer t :element-type 'character))
560         (result (replace x y :start1 1)))
561    (values (eqt x result) result))
562  t
563  "a123ef")
564
565(deftest replace-string.18
566  (let* ((x (copy-seq "abcdef"))
567         (y (make-array '(6) :initial-contents "123456"
568                        :fill-pointer 3
569                        :element-type 'character))
570         (result (replace x y :start1 1)))
571    (values (eqt x result) result))
572  t
573  "a123ef")
574
575(deftest replace-string.19
576  (let* ((x (copy-seq "abcdef"))
577         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
578    (values (eqt x result) result))
579  t
580  "bcddef")
581
582(deftest replace-string.21
583  (let* ((x (copy-seq "abcdef"))
584         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
585    (values (eqt x result) result))
586  t
587  "aabcef")
588
589(deftest replace-string.22
590  (do-special-strings
591   (s "abcdefg" nil)
592   (assert (eq s (replace s "XYZ")))
593   (assert (string= s "XYZdefg")))
594  nil)
595
596(deftest replace-string.23
597  (do-special-strings
598   (s "abcdefg" nil)
599   (assert (eq s (replace s "XYZ" :start1 1)))
600   (assert (string= s "aXYZefg")))
601  nil)
602
603(deftest replace-string.24
604  (do-special-strings
605   (s "abcdefg" nil)
606   (assert (eq s (replace s "XYZ" :start1 1 :end2 2)))
607   (assert (string= s "aXYdefg")))
608  nil)
609
610(deftest replace-string.25
611  (do-special-strings
612   (s "abcdefg" nil)
613   (assert (eq s (replace s "XYZ" :end1 2)))
614   (assert (string= s "XYcdefg")))
615  nil)
616
617(deftest replace-string.26
618  (do-special-strings
619   (s "abcdefg" nil)
620   (assert (eq s (replace s "XYZ" :start2 1)))
621   (assert (string= s "YZcdefg")))
622  nil)
623
624
625
626
627
628;;; Order of evaluation tests
629
630(deftest replace.order.1
631  (let ((i 0) a b)
632    (values
633     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
634              (progn (setf b (incf i)) (list 'e 'f)))
635     i a b))
636  (e f c) 2 1 2)
637
638(deftest replace.order.2
639  (let ((i 0) a b c d e f)
640    (values
641     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
642              (progn (setf b (incf i)) (list 'e 'f))
643              :start1 (progn (setf c (incf i)) 1)
644              :end1 (progn (setf d (incf i)) 3)
645              :start2 (progn (setf e (incf i)) 0)
646              :end2 (progn (setf f (incf i)) 2)
647              )
648     i a b c d e f))
649  (a e f) 6 1 2 3 4 5 6)
650
651(deftest replace.order.3
652  (let ((i 0) a b c d e f)
653    (values
654     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
655              (progn (setf b (incf i)) (list 'e 'f))
656              :end2 (progn (setf c (incf i)) 2)
657              :start2 (progn (setf d (incf i)) 0)
658              :end1 (progn (setf e (incf i)) 3)
659              :start1 (progn (setf f (incf i)) 1)
660              )
661     i a b c d e f))
662  (a e f) 6 1 2 3 4 5 6)
663
664;;; Keyword tests
665
666(deftest replace.allow-other-keys.1
667  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t)
668  "xyzdefg")
669
670(deftest replace.allow-other-keys.2
671  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys nil)
672  "xyzdefg")
673
674(deftest replace.allow-other-keys.3
675  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t :bad t)
676  "xyzdefg")
677
678(deftest replace.allow-other-keys.4
679  (replace (copy-seq "abcdefg") "xyz" :bad t :allow-other-keys t)
680  "xyzdefg")
681
682(deftest replace.allow-other-keys.5
683  (replace (copy-seq "abcdefg") "xyz" :bad1 t :allow-other-keys t
684           :bad2 t :allow-other-keys nil :bad3 nil)
685  "xyzdefg")
686
687(deftest replace.allow-other-keys.6
688  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t :start1 1)
689  "axyzefg")
690
691(deftest replace.keywords.7
692  (replace (copy-seq "abcdefg") "xyz" :start1 0 :start2 0 :end1 3 :end2 3
693           :start1 1 :start2 1 :end1 2 :end1 2)
694  "xyzdefg")
695
696
697
698
699;;; Error cases
700
701(deftest replace.error.1
702  (signals-error (replace) program-error)
703  t)
704
705(deftest replace.error.2
706  (signals-error (replace nil) program-error)
707  t)
708
709(deftest replace.error.3
710  (signals-error (replace nil nil :start) program-error)
711  t)
712
713(deftest replace.error.4
714  (signals-error (replace nil nil 'bad t) program-error)
715  t)
716
717(deftest replace.error.5
718  (signals-error (replace nil nil :allow-other-keys nil 'bad t) program-error)
719  t)
720
721(deftest replace.error.6
722  (signals-error (replace nil nil 1 2) program-error)
723  t)
724
Note: See TracBrowser for help on using the repository browser.