Shorten set-fdefn-fun
[sbcl.git] / tests / mop-19.impure-cload.lisp
blob12f2be51e2b3d56f3a8e95e478f24b050d1075bf
1 ;;;; miscellaneous side-effectful tests of the MOP
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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
8 ;;;; from CMU CL.
9 ;;;;
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.
17 (defpackage "MOP-19"
18 (:use "CL" "SB-MOP"))
20 (in-package "MOP-19")
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) ())
28 (defvar *calls* nil)
30 (defmethod reader-method-class ((c my-class) s &rest initargs)
31 (declare (ignore initargs))
32 (push (cons (slot-definition-name s) 'reader) *calls*)
33 (find-class 'my-reader))
34 (defmethod writer-method-class ((c my-class) s &rest initargs)
35 (declare (ignore initargs))
36 (push (cons (slot-definition-name s) 'writer) *calls*)
37 (find-class 'my-writer))
39 (defclass foo ()
40 ((a :reader a)
41 (b :writer b)
42 (c :accessor c))
43 (:metaclass my-class))
45 (assert (= (length *calls*) 4))
46 (assert (= (count 'a *calls* :key #'car) 1))
47 (assert (= (count 'b *calls* :key #'car) 1))
48 (assert (= (count 'c *calls* :key #'car) 2))
49 (assert (= (count 'reader *calls* :key #'cdr) 2))
50 (assert (= (count 'writer *calls* :key #'cdr) 2))
51 (let ((method (find-method #'a nil (list (find-class 'foo)))))
52 (assert (eq (class-of method) (find-class 'my-reader))))
53 (let ((method (find-method #'b nil (list (find-class t) (find-class 'foo)))))
54 (assert (eq (class-of method) (find-class 'my-writer))))
56 (defclass my-other-class (my-class) ())
57 (defmethod validate-superclass ((a my-other-class) (b standard-class)) t)
59 (defclass my-other-reader (standard-reader-method) ())
61 (defclass my-direct-slot-definition (standard-direct-slot-definition) ())
63 (defmethod direct-slot-definition-class ((c my-other-class) &rest args)
64 (declare (ignore args))
65 (find-class 'my-direct-slot-definition))
67 (defmethod reader-method-class :around
68 (class (s my-direct-slot-definition) &rest initargs)
69 (declare (ignore initargs))
70 (find-class 'my-other-reader))
72 (defclass bar ()
73 ((d :reader d)
74 (e :writer e))
75 (:metaclass my-other-class))
77 (let ((method (find-method #'d nil (list (find-class 'bar)))))
78 (assert (eq (class-of method) (find-class 'my-other-reader))))
79 (let ((method (find-method #'e nil (list (find-class t) (find-class 'bar)))))
80 (assert (eq (class-of method) (find-class 'my-writer))))