branch: elpa/buttercup
commit f44e65d6c7e0fa7482308cf69f7b309f68899d83
Author: Jorgen Schaefer <[email protected]>
Commit: Jorgen Schaefer <[email protected]>
Unit tests for define-matcher and apply-matcher.
---
buttercup-test.el | 27 +++++++++++++++++++++------
buttercup.el | 3 +++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/buttercup-test.el b/buttercup-test.el
index 0b123b9..abc6daf 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -82,11 +82,26 @@
'buttercup-failed "Explanation")))
(describe "The `buttercup-define-matcher' macro"
- (it "should add a buttercup-matcher property"
- (buttercup-define-matcher :test-matcher (a b)
- (+ a b))
+ (buttercup-define-matcher :test-matcher (a b)
+ (+ a b))
- (expect (funcall (get :test-matcher 'buttercup-matcher)
- 1 2)
+ (it "should create a matcher usable by apply-matcher"
+ (expect (buttercup--apply-matcher :test-matcher '(1 2))
:to-equal
- 3)))
+ 3))
+
+ (describe "The `buttercup--apply-matcher'"
+ (it "should work with functions"
+ (expect (buttercup--apply-matcher #'+ '(1 2))
+ :to-equal
+ 3))
+
+ (it "should work with matchers"
+ (expect (buttercup--apply-matcher :test-matcher '(1 2))
+ :to-equal
+ 3))
+
+ (it "should fail if the matcher is not defined"
+ (expect (lambda ()
+ (buttercup--apply-matcher :not-defined '(1 2)))
+ :to-throw))))
diff --git a/buttercup.el b/buttercup.el
index 4997e6d..baff39e 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -104,7 +104,10 @@ should describe why a negated matcher failed."
,@body)))
(defun buttercup--apply-matcher (matcher args)
+ "Apply MATCHER to ARGS.
+MATCHER is either a matcher defined with
+`buttercup-define-matcher', or a function."
(let ((function (or (get matcher 'buttercup-matcher)
matcher)))
(when (not (functionp function))