rplaca.lsp 975 Bytes
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 21:29:43 2003
;;;; Contains: Tests of RPLACA

6

7

8

9

10 11 12 13
(deftest rplaca.1
  (let ((x (cons 'a 'b)))
    (let ((y x))
      (and (eqt (rplaca x 'c) y)
sds's avatar
sds committed
14 15 16
           (eqt x y)
           (eqt (car x) 'c)
           (eqt (cdr x) 'b))))
17 18 19 20
  t)

(deftest rplaca.order.1
  (let ((x (cons 'a 'b))
sds's avatar
sds committed
21
        (i 0) a b)
22 23
    (values
     (rplaca (progn (setf a (incf i)) x)
sds's avatar
sds committed
24
             (progn (setf b (incf i)) 'c))
25 26 27
     i a b))
  (c . b) 2 1 2)

pfdietz's avatar
pfdietz committed
28
;; rplaca on a non-cons is a type error
29
(deftest rplaca.error.1
30
  (check-type-error #'(lambda (x) (rplaca x 1)) #'consp)
31 32 33
  nil)

(deftest rplaca.error.2
34 35
  (signals-error (rplaca) program-error)
  t)
36 37

(deftest rplaca.error.3
38 39
  (signals-error (rplaca (cons 'a 'b)) program-error)
  t)
40 41

(deftest rplaca.error.4
42 43
  (signals-error (rplaca (cons 'a 'b) (cons 'c 'd) 'garbage) program-error)
  t)
44 45

(deftest rplaca.error.6
46 47
  (signals-error (locally (rplaca 'a 1) t) type-error)
  t)