Debian Codegraph @

src/tests/normal-tests/clos.lsp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;; Author: Daniel Kochmański
5 ;;;; Created: 2023-01-19
6 ;;;; Contains: CLOS tests
7
8 (in-package #:cl-test)
9
10 (suite 'clos)
11
12
13 ;;; Method combination long form
14
15 ;;; Check whether different types of wildcard patterns are correctly handled.
16 ;;; Most notably the symbol * in a pattern matches any method qualifier on
17 ;;; that position.
18 (ext:with-clean-symbols (combin gf)
19 (test clos.0001.combin/wildcard
20 (define-method-combination combin ()
21 ((p1 (:wild :no))
22 (p2 (:wild * *))
23 (p3 (:wild . *))
24 (pr *))
25 `(list ,(length p1)
26 ,(length p2)
27 ,(length p3)
28 ,(length pr)))
29 (defgeneric gf ()
30 (:method-combination combin))
31 (finishes (defmethod gf :wild :no ())) ; p1
32 (finishes (defmethod gf :wild :x :y ())) ; p2
33 (finishes (defmethod gf :wild ())) ; p3
34 (finishes (defmethod gf :wild :foobar ())) ; p3
35 (finishes (defmethod gf :wild :no :a :b ())) ; p3
36 (finishes (defmethod gf :xxx :yyy 34 23 ())) ; p4
37 (is-equal '(1 1 3 1) (gf))))
38
39 ;;; This test checks whether define-method-combination handles arguments
40 ;;; :GENERIC-FUNCTION and :ARGUMENTS &WHOLE ARGS.
41 (ext:with-clean-symbols (combin f1 f2)
42 (test clos.0002.combin/arguments
43 (define-method-combination combin ()
44 ((method-list *))
45 (:arguments &whole args)
46 (:generic-function gf)
47 `(list* ,gf ,args))
48 (defgeneric f1 (a &key key-1)
49 (:method-combination combin)
50 (:method (a &key key-1 key-2)
51 (declare (ignore a key-1 key-2))))
52 (is-equal (list #'f1 1 :key-1 2) (f1 1 :key-1 2))))