replace.lsp 17.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Aug 27 16:11:38 2002
;;;; Contains: Tests for REPLACE

(in-package :cl-test)

(deftest replace-list.1
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
10
         (result (replace x '(x y z))))
11
    (values (eqt x result) result))
12 13 14 15 16
  t
  (x y z d e f g))

(deftest replace-list.2
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
17
         (result (replace x '(x y z) :start1 1)))
18
    (values (eqt x result) result))
19 20 21 22 23
  t
  (a x y z e f g))

(deftest replace-list.3
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
24
         (result (replace x '(x y z) :start1 4)))
25
    (values (eqt x result) result))
26 27 28 29 30
  t
  (a b c d x y z))

(deftest replace-list.4
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
31
         (result (replace x '(x y z) :start1 5)))
32
    (values (eqt x result) result))
33 34 35 36 37
  t
  (a b c d e x y))

(deftest replace-list.5
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
38
         (result (replace x '(x y z) :start1 6)))
39
    (values (eqt x result) result))
40 41 42 43 44
  t
  (a b c d e f x))

(deftest replace-list.6
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
45
         (result (replace x #(x y z) :start1 2)))
46
    (values (eqt x result) result))
47 48 49 50 51 52 53 54 55
  t
  (a b x y z f g))

(deftest replace-list.7
  (replace nil #(x y z))
  nil)

(deftest replace-list.8
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
56
         (result (replace x '(x y z) :end1 1)))
57
    (values (eqt x result) result))
58 59 60 61 62
  t
  (x b c d e f g))

(deftest replace-list.9
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
63
         (result (replace x '(x y z) :start1 3 :end1 4)))
64
    (values (eqt x result) result))
65 66 67 68 69
  t
  (a b c x e f g))

(deftest replace-list.10
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
70
         (result (replace x '(x y z) :start1 0 :end1 5)))
71
    (values (eqt x result) result))
72 73 74 75 76 77
  t
  (x y z d e f g))


(deftest replace-list.11
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
78
         (result (replace x '(x y z) :start2 1)))
79
    (values (eqt x result) result))
80 81 82 83 84
  t
  (y z c d e f g))

(deftest replace-list.12
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
85
         (result (replace x '(x y z) :start2 1 :end1 nil)))
86
    (values (eqt x result) result))
87 88 89 90 91
  t
  (y z c d e f g))

(deftest replace-list.13
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
92
         (result (replace x '(x y z) :start2 1 :end2 nil)))
93
    (values (eqt x result) result))
94 95 96 97 98
  t
  (y z c d e f g))

(deftest replace-list.14
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
99
         (result (replace x '(x y z) :start2 1 :end2 2)))
100
    (values (eqt x result) result))
101 102 103 104 105
  t
  (y b c d e f g))

(deftest replace-list.15
  (let* ((x (copy-seq '(a b c d e f g)))
sds's avatar
sds committed
106
         (result (replace x '(x y z) :start1 4 :end1 5 :start2 1 :end2 2)))
107
    (values (eqt x result) result))
108 109 110
  t
  (a b c d y f g))

111 112
(deftest replace-list.16
  (let* ((x (copy-seq '(a b c d e f)))
sds's avatar
sds committed
113 114
         (y #(1 2 3))
         (result (replace x y :start1 1)))
115 116 117 118 119 120
    (values (eqt x result) result))
  t
  (a 1 2 3 e f))

(deftest replace-list.17
  (let* ((x (copy-seq '(a b c d e f)))
sds's avatar
sds committed
121 122 123
         (y (make-array '(3) :initial-contents '(1 2 3)
                        :fill-pointer t))
         (result (replace x y :start1 1)))
124 125 126 127 128 129
    (values (eqt x result) result))
  t
  (a 1 2 3 e f))

(deftest replace-list.18
  (let* ((x (copy-seq '(a b c d e f)))
sds's avatar
sds committed
130 131 132
         (y (make-array '(6) :initial-contents '(1 2 3 4 5 6)
                        :fill-pointer 3))
         (result (replace x y :start1 1)))
133 134 135 136 137 138
    (values (eqt x result) result))
  t
  (a 1 2 3 e f))

(deftest replace-list.19
  (let* ((x (copy-seq '(a b c d e f)))
sds's avatar
sds committed
139
         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
140 141 142 143 144 145
    (values (eqt x result) result))
  t
  (b c d d e f))

(deftest replace-list.20
  (let* ((x (copy-seq '(a b c d e f)))
sds's avatar
sds committed
146
         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
147 148 149 150
    (values (eqt x result) result))
  t
  (a a b c e f))

151 152 153 154 155

;;; Tests of vectors

(deftest replace-vector.1
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
156
         (result (replace x #(x y z))))
157
    (values (eqt x result) result))
158 159 160 161 162
  t
  #(x y z d e f g))

(deftest replace-vector.2
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
163
         (result (replace x #(x y z) :start1 1)))
164
    (values (eqt x result) result))
165 166 167 168 169
  t
  #(a x y z e f g))

(deftest replace-vector.3
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
170
         (result (replace x #(x y z) :start1 4)))
171
    (values (eqt x result) result))
172 173 174 175 176
  t
  #(a b c d x y z))

(deftest replace-vector.4
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
177
         (result (replace x #(x y z) :start1 5)))
178
    (values (eqt x result) result))
179 180 181 182 183
  t
  #(a b c d e x y))

(deftest replace-vector.5
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
184
         (result (replace x #(x y z) :start1 6)))
185
    (values (eqt x result) result))
186 187 188 189 190
  t
  #(a b c d e f x))

(deftest replace-vector.6
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
191
         (result (replace x '(x y z) :start1 2)))
192
    (values (eqt x result) result))
193 194 195 196 197 198 199 200 201
  t
  #(a b x y z f g))

(deftest replace-vector.7
  (replace #() #(x y z))
  #())

(deftest replace-vector.8
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
202
         (result (replace x #(x y z) :end1 1)))
203
    (values (eqt x result) result))
204 205 206 207 208
  t
  #(x b c d e f g))

(deftest replace-vector.9
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
209
         (result (replace x #(x y z) :start1 3 :end1 4)))
210
    (values (eqt x result) result))
211 212 213 214 215
  t
  #(a b c x e f g))

(deftest replace-vector.10
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
216
         (result (replace x #(x y z) :start1 0 :end1 5)))
217
    (values (eqt x result) result))
218 219 220 221 222 223
  t
  #(x y z d e f g))


(deftest replace-vector.11
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
224
         (result (replace x #(x y z) :start2 1)))
225
    (values (eqt x result) result))
226 227 228 229 230
  t
  #(y z c d e f g))

(deftest replace-vector.12
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
231
         (result (replace x #(x y z) :start2 1 :end1 nil)))
232
    (values (eqt x result) result))
233 234 235 236 237
  t
  #(y z c d e f g))

(deftest replace-vector.13
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
238
         (result (replace x #(x y z) :start2 1 :end2 nil)))
239
    (values (eqt x result) result))
240 241 242 243 244
  t
  #(y z c d e f g))

(deftest replace-vector.14
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
245
         (result (replace x #(x y z) :start2 1 :end2 2)))
246
    (values (eqt x result) result))
247 248 249 250 251
  t
  #(y b c d e f g))

(deftest replace-vector.15
  (let* ((x (copy-seq #(a b c d e f g)))
sds's avatar
sds committed
252
         (result (replace x #(x y z) :start1 4 :end1 5 :start2 1 :end2 2)))
253
    (values (eqt x result) result))
254 255 256
  t
  #(a b c d y f g))

257 258
(deftest replace-vector.16
  (let* ((x (copy-seq #(a b c d e f)))
sds's avatar
sds committed
259 260
         (y '(1 2 3))
         (result (replace x y :start1 1)))
261 262 263 264 265 266
    (values (eqt x result) result))
  t
  #(a 1 2 3 e f))

(deftest replace-vector.17
  (let* ((x (copy-seq #(a b c d e f)))
sds's avatar
sds committed
267 268 269
         (y (make-array '(3) :initial-contents '(1 2 3)
                        :fill-pointer t))
         (result (replace x y :start1 1)))
270 271 272 273 274 275
    (values (eqt x result) result))
  t
  #(a 1 2 3 e f))

(deftest replace-vector.18
  (let* ((x (copy-seq #(a b c d e f)))
sds's avatar
sds committed
276 277 278
         (y (make-array '(6) :initial-contents '(1 2 3 4 5 6)
                        :fill-pointer 3))
         (result (replace x y :start1 1)))
279 280 281 282 283 284
    (values (eqt x result) result))
  t
  #(a 1 2 3 e f))

(deftest replace-vector.19
  (let* ((x (copy-seq #(a b c d e f)))
sds's avatar
sds committed
285
         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
286 287 288 289 290 291
    (values (eqt x result) result))
  t
  #(b c d d e f))

(deftest replace-vector.21
  (let* ((x (copy-seq #(a b c d e f)))
sds's avatar
sds committed
292
         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
293 294 295 296 297
    (values (eqt x result) result))
  t
  #(a a b c e f))

;;; tests on bit vectors
298

299
(deftest replace-bit-vector.1
300
  (let* ((x (copy-seq #*1101001))
sds's avatar
sds committed
301
         (result (replace x #*011)))
302
    (values (eqt x result) result))
303 304 305
  t
  #*0111001)

306
(deftest replace-bit-vector.2
307
  (let* ((x (copy-seq #*1101001))
sds's avatar
sds committed
308
         (result (replace x #*011 :start1 1)))
309
    (values (eqt x result) result))
310 311 312
  t
  #*1011001)

313
(deftest replace-bit-vector.3
314
  (let* ((x (copy-seq #*1101001))
sds's avatar
sds committed
315
         (result (replace x #*011 :start1 4)))
316
    (values (eqt x result) result))
317 318 319
  t
  #*1101011)

320
(deftest replace-bit-vector.4
321
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
322
         (result (replace x #*111 :start1 5)))
323
    (values (eqt x result) result))
324 325 326
  t
  #*0000011)

327
(deftest replace-bit-vector.5
328
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
329
         (result (replace x #*100 :start1 6)))
330
    (values (eqt x result) result))
331 332 333
  t
  #*0000001)

334
(deftest replace-bit-vector.6
335
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
336
         (result (replace x '(1 1 1) :start1 2)))
337
    (values (eqt x result) result))
338 339 340
  t
  #*0011100)

341
(deftest replace-bit-vector.7
342 343 344
  (replace #* #*111)
  #*)

345
(deftest replace-bit-vector.8
346
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
347
         (result (replace x #*111 :end1 1)))
348
    (values (eqt x result) result))
349 350 351
  t
  #*1000000)

352
(deftest replace-bit-vector.9
353
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
354
         (result (replace x #*110 :start1 3 :end1 4)))
355
    (values (eqt x result) result))
356 357 358
  t
  #*0001000)

359
(deftest replace-bit-vector.10
360
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
361
         (result (replace x #*111 :start1 0 :end1 5)))
362
    (values (eqt x result) result))
363 364 365 366
  t
  #*1110000)


367
(deftest replace-bit-vector.11
368
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
369
         (result (replace x #*011 :start2 1)))
370
    (values (eqt x result) result))
371 372 373
  t
  #*1100000)

374
(deftest replace-bit-vector.12
375
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
376
         (result (replace x #*011 :start2 1 :end1 nil)))
377
    (values (eqt x result) result))
378 379 380
  t
  #*1100000)

381
(deftest replace-bit-vector.13
382
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
383
         (result (replace x #*011 :start2 1 :end2 nil)))
384
    (values (eqt x result) result))
385 386 387
  t
  #*1100000)

388
(deftest replace-bit-vector.14
389
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
390
         (result (replace x #*011 :start2 1 :end2 2)))
391
    (values (eqt x result) result))
392 393 394
  t
  #*1000000)

395
(deftest replace-bit-vector.15
396
  (let* ((x (copy-seq #*0000000))
sds's avatar
sds committed
397
         (result (replace x #*011 :start1 4 :end1 5 :start2 1 :end2 2)))
398
    (values (eqt x result) result))
399 400 401
  t
  #*0000100)

402 403
(deftest replace-bit-vector.16
  (let* ((x (copy-seq #*001011))
sds's avatar
sds committed
404 405
         (y '(1 0 1))
         (result (replace x y :start1 1)))
406 407 408 409 410 411
    (values (eqt x result) result))
  t
  #*010111)

(deftest replace-bit-vector.17
  (let* ((x (copy-seq #*001011))
sds's avatar
sds committed
412 413 414
         (y (make-array '(3) :initial-contents '(1 0 1)
                        :fill-pointer t :element-type 'bit))
         (result (replace x y :start1 1)))
415 416 417 418 419 420
    (values (eqt x result) result))
  t
  #*010111)

(deftest replace-bit-vector.18
  (let* ((x (copy-seq #*001011))
sds's avatar
sds committed
421 422 423 424
         (y (make-array '(6) :initial-contents '(1 0 1 0 0 1)
                        :fill-pointer 3
                        :element-type 'bit))
         (result (replace x y :start1 1)))
425 426 427 428 429 430
    (values (eqt x result) result))
  t
  #*010111)

(deftest replace-bit-vector.19
  (let* ((x (copy-seq #*001011))
sds's avatar
sds committed
431
         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
432 433 434 435 436 437
    (values (eqt x result) result))
  t
  #*010011)

(deftest replace-bit-vector.21
  (let* ((x (copy-seq #*001011))
sds's avatar
sds committed
438
         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
439 440 441 442
    (values (eqt x result) result))
  t
  #*000111)

443 444 445 446
;;; Tests on strings

(deftest replace-string.1
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
447
         (result (replace x "xyz")))
448
    (values (eqt x result) result))
449 450 451 452 453
  t
  "xyzdefg")

(deftest replace-string.2
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
454
         (result (replace x "xyz" :start1 1)))
455
    (values (eqt x result) result))
456 457 458 459 460
  t
  "axyzefg")

(deftest replace-string.3
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
461
         (result (replace x "xyz" :start1 4)))
462
    (values (eqt x result) result))
463 464 465 466 467
  t
  "abcdxyz")

(deftest replace-string.4
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
468
         (result (replace x "xyz" :start1 5)))
469
    (values (eqt x result) result))
470 471 472 473 474
  t
  "abcdexy")

(deftest replace-string.5
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
475
         (result (replace x "xyz" :start1 6)))
476
    (values (eqt x result) result))
477 478 479 480 481
  t
  "abcdefx")

(deftest replace-string.6
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
482
         (result (replace x '(#\x #\y #\z) :start1 2)))
483
    (values (eqt x result) result))
484 485 486 487 488 489 490 491 492
  t
  "abxyzfg")

(deftest replace-string.7
  (replace "" "xyz")
  "")

(deftest replace-string.8
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
493
         (result (replace x "xyz" :end1 1)))
494
    (values (eqt x result) result))
495 496 497 498 499
  t
  "xbcdefg")

(deftest replace-string.9
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
500
         (result (replace x "xyz" :start1 3 :end1 4)))
501
    (values (eqt x result) result))
502 503 504 505 506
  t
  "abcxefg")

(deftest replace-string.10
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
507
         (result (replace x "xyz" :start1 0 :end1 5)))
508
    (values (eqt x result) result))
509 510 511 512 513 514
  t
  "xyzdefg")


(deftest replace-string.11
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
515
         (result (replace x "xyz" :start2 1)))
516
    (values (eqt x result) result))
517 518 519 520 521
  t
  "yzcdefg")

(deftest replace-string.12
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
522
         (result (replace x "xyz" :start2 1 :end1 nil)))
523
    (values (eqt x result) result))
524 525 526 527 528
  t
  "yzcdefg")

(deftest replace-string.13
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
529
         (result (replace x "xyz" :start2 1 :end2 nil)))
530
    (values (eqt x result) result))
531 532 533 534 535
  t
  "yzcdefg")

(deftest replace-string.14
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
536
         (result (replace x "xyz" :start2 1 :end2 2)))
537
    (values (eqt x result) result))
538 539 540 541 542
  t
  "ybcdefg")

(deftest replace-string.15
  (let* ((x (copy-seq "abcdefg"))
sds's avatar
sds committed
543
         (result (replace x "xyz" :start1 4 :end1 5 :start2 1 :end2 2)))
544
    (values (eqt x result) result))
545 546
  t
  "abcdyfg")
547 548 549

(deftest replace-string.16
  (let* ((x (copy-seq "abcdef"))
sds's avatar
sds committed
550 551
         (y (coerce "123" 'list))
         (result (replace x y :start1 1)))
552 553 554 555 556 557
    (values (eqt x result) result))
  t
  "a123ef")

(deftest replace-string.17
  (let* ((x (copy-seq "abcdef"))
sds's avatar
sds committed
558 559 560
         (y (make-array '(3) :initial-contents '(#\1 #\2 #\3)
                        :fill-pointer t :element-type 'character))
         (result (replace x y :start1 1)))
561 562 563 564 565 566
    (values (eqt x result) result))
  t
  "a123ef")

(deftest replace-string.18
  (let* ((x (copy-seq "abcdef"))
sds's avatar
sds committed
567 568 569 570
         (y (make-array '(6) :initial-contents "123456"
                        :fill-pointer 3
                        :element-type 'character))
         (result (replace x y :start1 1)))
571 572 573 574 575 576
    (values (eqt x result) result))
  t
  "a123ef")

(deftest replace-string.19
  (let* ((x (copy-seq "abcdef"))
sds's avatar
sds committed
577
         (result (replace x x :start1 0 :end1 3 :start2 1 :end2 4)))
578 579 580 581 582 583
    (values (eqt x result) result))
  t
  "bcddef")

(deftest replace-string.21
  (let* ((x (copy-seq "abcdef"))
sds's avatar
sds committed
584
         (result (replace x x :start1 1 :end1 4 :start2 0 :end2 3)))
585 586 587
    (values (eqt x result) result))
  t
  "aabcef")
588

589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
(deftest replace-string.22
  (do-special-strings
   (s "abcdefg" nil)
   (assert (eq s (replace s "XYZ")))
   (assert (string= s "XYZdefg")))
  nil)

(deftest replace-string.23
  (do-special-strings
   (s "abcdefg" nil)
   (assert (eq s (replace s "XYZ" :start1 1)))
   (assert (string= s "aXYZefg")))
  nil)

(deftest replace-string.24
  (do-special-strings
   (s "abcdefg" nil)
   (assert (eq s (replace s "XYZ" :start1 1 :end2 2)))
   (assert (string= s "aXYdefg")))
  nil)

(deftest replace-string.25
  (do-special-strings
   (s "abcdefg" nil)
   (assert (eq s (replace s "XYZ" :end1 2)))
   (assert (string= s "XYcdefg")))
  nil)

(deftest replace-string.26
  (do-special-strings
   (s "abcdefg" nil)
   (assert (eq s (replace s "XYZ" :start2 1)))
   (assert (string= s "YZcdefg")))
  nil)





628 629 630 631 632 633
;;; Order of evaluation tests

(deftest replace.order.1
  (let ((i 0) a b)
    (values
     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
sds's avatar
sds committed
634
              (progn (setf b (incf i)) (list 'e 'f)))
635 636 637 638 639 640 641
     i a b))
  (e f c) 2 1 2)

(deftest replace.order.2
  (let ((i 0) a b c d e f)
    (values
     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
sds's avatar
sds committed
642 643 644 645 646 647
              (progn (setf b (incf i)) (list 'e 'f))
              :start1 (progn (setf c (incf i)) 1)
              :end1 (progn (setf d (incf i)) 3)
              :start2 (progn (setf e (incf i)) 0)
              :end2 (progn (setf f (incf i)) 2)
              )
648 649 650 651 652 653 654
     i a b c d e f))
  (a e f) 6 1 2 3 4 5 6)

(deftest replace.order.3
  (let ((i 0) a b c d e f)
    (values
     (replace (progn (setf a (incf i)) (list 'a 'b 'c))
sds's avatar
sds committed
655 656 657 658 659 660
              (progn (setf b (incf i)) (list 'e 'f))
              :end2 (progn (setf c (incf i)) 2)
              :start2 (progn (setf d (incf i)) 0)
              :end1 (progn (setf e (incf i)) 3)
              :start1 (progn (setf f (incf i)) 1)
              )
661 662 663
     i a b c d e f))
  (a e f) 6 1 2 3 4 5 6)

664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
;;; Keyword tests

(deftest replace.allow-other-keys.1
  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t)
  "xyzdefg")

(deftest replace.allow-other-keys.2
  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys nil)
  "xyzdefg")

(deftest replace.allow-other-keys.3
  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t :bad t)
  "xyzdefg")

(deftest replace.allow-other-keys.4
  (replace (copy-seq "abcdefg") "xyz" :bad t :allow-other-keys t)
  "xyzdefg")

(deftest replace.allow-other-keys.5
  (replace (copy-seq "abcdefg") "xyz" :bad1 t :allow-other-keys t
sds's avatar
sds committed
684
           :bad2 t :allow-other-keys nil :bad3 nil)
685 686 687 688 689 690 691 692
  "xyzdefg")

(deftest replace.allow-other-keys.6
  (replace (copy-seq "abcdefg") "xyz" :allow-other-keys t :start1 1)
  "axyzefg")

(deftest replace.keywords.7
  (replace (copy-seq "abcdefg") "xyz" :start1 0 :start2 0 :end1 3 :end2 3
sds's avatar
sds committed
693
           :start1 1 :start2 1 :end1 2 :end1 2)
694 695 696 697 698
  "xyzdefg")




699 700 701
;;; Error cases

(deftest replace.error.1
702 703
  (signals-error (replace) program-error)
  t)
704 705

(deftest replace.error.2
706 707
  (signals-error (replace nil) program-error)
  t)
708 709

(deftest replace.error.3
710 711
  (signals-error (replace nil nil :start) program-error)
  t)
712 713

(deftest replace.error.4
714 715
  (signals-error (replace nil nil 'bad t) program-error)
  t)
716 717

(deftest replace.error.5
718 719
  (signals-error (replace nil nil :allow-other-keys nil 'bad t) program-error)
  t)
720 721

(deftest replace.error.6
722 723
  (signals-error (replace nil nil 1 2) program-error)
  t)
724