Fix make-array transforms.
[sbcl.git] / tests / mop-19.impure-cload.lisp
1 ;;;; miscellaneous side-effectful tests of the MOP
2
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.
13
14 ;;; this file tests the accessor method class portion of the protocol
15 ;;; for Initialization of Class Metaobjects.
16
17 (defpackage "MOP-19"
18   (:use "CL" "SB-MOP"))
19
20 (in-package "MOP-19")
21
22 (defclass my-class (standard-class) ())
23 (defmethod validate-superclass ((a my-class) (b standard-class)) t)
24
25 (defclass my-reader (standard-reader-method) ())
26 (defclass my-writer (standard-writer-method) ())
27
28 (defvar *calls* nil)
29
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))
36
37 (defclass foo ()
38   ((a :reader a)
39    (b :writer b)
40    (c :accessor c))
41   (:metaclass my-class))
42
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))))
53 \f
54 (defclass my-other-class (my-class) ())
55 (defmethod validate-superclass ((a my-other-class) (b standard-class)) t)
56
57 (defclass my-other-reader (standard-reader-method) ())
58
59 (defclass my-direct-slot-definition (standard-direct-slot-definition) ())
60
61 (defmethod direct-slot-definition-class ((c my-other-class) &rest args)
62   (find-class 'my-direct-slot-definition))
63
64 (defmethod reader-method-class :around
65     (class (s my-direct-slot-definition) &rest initargs)
66   (find-class 'my-other-reader))
67
68 (defclass bar ()
69   ((d :reader d)
70    (e :writer e))
71   (:metaclass my-other-class))
72
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))))