1 ;;;; miscellaneous side-effectful tests of the MOP
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;; this file tests the accessor method class portion of the protocol
15 ;;; for Initialization of Class Metaobjects.
22 (defclass my-class
(standard-class) ())
23 (defmethod validate-superclass ((a my-class
) (b standard-class
)) t
)
25 (defclass my-reader
(standard-reader-method) ())
26 (defclass my-writer
(standard-writer-method) ())
30 (defmethod reader-method-class ((c my-class
) s
&rest initargs
)
31 (push (cons (slot-definition-name s
) 'reader
) *calls
*)
32 (find-class 'my-reader
))
33 (defmethod writer-method-class ((c my-class
) s
&rest initargs
)
34 (push (cons (slot-definition-name s
) 'writer
) *calls
*)
35 (find-class 'my-writer
))
41 (:metaclass my-class
))
43 (assert (= (length *calls
*) 4))
44 (assert (= (count 'a
*calls
* :key
#'car
) 1))
45 (assert (= (count 'b
*calls
* :key
#'car
) 1))
46 (assert (= (count 'c
*calls
* :key
#'car
) 2))
47 (assert (= (count 'reader
*calls
* :key
#'cdr
) 2))
48 (assert (= (count 'writer
*calls
* :key
#'cdr
) 2))
49 (let ((method (find-method #'a nil
(list (find-class 'foo
)))))
50 (assert (eq (class-of method
) (find-class 'my-reader
))))
51 (let ((method (find-method #'b nil
(list (find-class t
) (find-class 'foo
)))))
52 (assert (eq (class-of method
) (find-class 'my-writer
))))
54 (defclass my-other-class
(my-class) ())
55 (defmethod validate-superclass ((a my-other-class
) (b standard-class
)) t
)
57 (defclass my-other-reader
(standard-reader-method) ())
59 (defclass my-direct-slot-definition
(standard-direct-slot-definition) ())
61 (defmethod direct-slot-definition-class ((c my-other-class
) &rest args
)
62 (find-class 'my-direct-slot-definition
))
64 (defmethod reader-method-class :around
65 (class (s my-direct-slot-definition
) &rest initargs
)
66 (find-class 'my-other-reader
))
71 (:metaclass my-other-class
))
73 (let ((method (find-method #'d nil
(list (find-class 'bar
)))))
74 (assert (eq (class-of method
) (find-class 'my-other-reader
))))
75 (let ((method (find-method #'e nil
(list (find-class t
) (find-class 'bar
)))))
76 (assert (eq (class-of method
) (find-class 'my-writer
))))