next-method-p.lsp 1.71 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat May 31 08:04:45 2003
;;;; Contains: Tests of NEXT-METHOD-P

(in-package :cl-test)

(defgeneric nmp-gf-01 (x)
  (:method ((x integer)) (notnot-mv (next-method-p)))
  (:method ((x number)) 'foo)
  (:method ((x symbol)) (next-method-p)))

(deftest next-method-p.1
  (nmp-gf-01 10)
  t)

(deftest next-method-p.2
  (nmp-gf-01 1.2)
  foo)

(deftest next-method-p.3
  (nmp-gf-01 'a)
  nil)

(defgeneric nmp-gf-02 (x y)
  (:method ((x integer) (y symbol)) (notnot-mv (next-method-p)))
  (:method ((x number) (y (eql nil))) 'foo))

(deftest next-method-p.4
  (nmp-gf-02 10 nil)
  t)

(deftest next-method-p.5
  (nmp-gf-02 10 'a)
  nil)

(defgeneric nmp-gf-03 (x y)
  (:method ((x integer) (y symbol)) #'next-method-p)
39
  (:method ((x t) (y (eql nil))) (constantly 1)))
pfdietz's avatar
pfdietz committed
40 41

(deftest next-method-p.6
42
  (notnot-mv (funcall (the function (nmp-gf-03 10 nil))))
pfdietz's avatar
pfdietz committed
43 44 45 46 47 48
  t)
  
(deftest next-method-p.7
  (funcall (nmp-gf-03 10 'a))
  nil)

49
(defgeneric nmp-gf-04 (x y))
pfdietz's avatar
pfdietz committed
50
(defmethod nmp-gf-04 ((x integer) (y symbol)) #'next-method-p)
51
(defmethod nmp-gf-04 ((x t) (y (eql nil))) (constantly 2))
pfdietz's avatar
pfdietz committed
52 53

(deftest next-method-p.8
54
  (notnot-mv (funcall (the function (nmp-gf-04 10 nil))))
pfdietz's avatar
pfdietz committed
55 56 57 58 59 60 61 62
  t)
  
(deftest next-method-p.9
  (funcall (nmp-gf-04 10 'a))
  nil)

;; With AROUND methods

63
(defgeneric nmp-gf-05 (x))
pfdietz's avatar
pfdietz committed
64 65 66 67 68 69 70 71 72 73 74 75
(defmethod nmp-gf-05 :around ((x number)) (notnot-mv (next-method-p)))
(defmethod nmp-gf-05 ((x integer)) 'foo)

(deftest next-method-p.10
  (nmp-gf-05 10)
  t)

;; Need to also test next-method-p in builtin method combinations

;;; Error tests

(deftest next-method-p.error.1
76
  (signals-error
pfdietz's avatar
pfdietz committed
77 78
   (progn
     (eval '(defmethod nmp-gf-06 ((x t)) (next-method-p nil)))
79 80 81
     (nmp-gf-06 nil))
   program-error)
  t)