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

(in-package :cl-test)

8 9
(compile-and-load "cons-aux.lsp")

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
(deftest rplaca.1
  (let ((x (cons 'a 'b)))
    (let ((y x))
      (and (eqt (rplaca x 'c) y)
	   (eqt x y)
	   (eqt (car x) 'c)
	   (eqt (cdr x) 'b))))
  t)

(deftest rplaca.order.1
  (let ((x (cons 'a 'b))
	(i 0) a b)
    (values
     (rplaca (progn (setf a (incf i)) x)
	     (progn (setf b (incf i)) 'c))
     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)