-
Notifications
You must be signed in to change notification settings - Fork 0
/
satisfying.lisp
33 lines (27 loc) · 938 Bytes
/
satisfying.lisp
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
(defpackage :fiveam-matchers/satisfying
(:use #:cl)
(:import-from #:fiveam-matchers/core
#:describe-mismatch
#:describe-self
#:matchesp
#:matcher)
(:local-nicknames (#:a #:alexandria)))
(in-package :fiveam-matchers/satisfying)
(defclass satisfying (matcher)
((expr :initarg :expr
:reader expr)
(predicate :initarg :predicate
:reader predicate)))
(defmacro satisfying (expr)
`(make-instance 'satisfying
:expr ',expr
:predicate (lambda (*)
,expr)))
(defun expr-str (self)
(prin1-to-string (expr self)))
(defmethod matchesp ((self satisfying) val)
(funcall (predicate self) val))
(defmethod describe-self ((self satisfying))
`("satisfies " ,(expr-str self)))
(defmethod describe-mismatch ((self satisfying) value)
`(,(expr-str self) " was false for " ,value))