[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup c1abc2a 033/340: Refactoring of spy context acce
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup c1abc2a 033/340: Refactoring of spy context accessors. |
Date: |
Thu, 16 Dec 2021 14:58:59 -0500 (EST) |
branch: elpa/buttercup
commit c1abc2af748437943720d8fe7f266b67a519e9c4
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
Refactoring of spy context accessors.
---
buttercup.el | 64 ++++++++++++++++++++++++++----------------------------------
1 file changed, 28 insertions(+), 36 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index d5b2f5f..2f66314 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -373,8 +373,8 @@ A disabled spec is not run."
;;;;;;;;;
;;; Spies
-(defvar buttercup--spy-calls (make-hash-table :test 'eq
- :weakness 'key)
+(defvar buttercup--spy-contexts (make-hash-table :test 'eq
+ :weakness 'key)
"A mapping of currently-defined spies to their contexts.")
(cl-defstruct spy-context
@@ -436,7 +436,7 @@ KEYWORD can have one of the following values:
(setq this-spy-function
(lambda (&rest args)
(let ((return-value (apply fake-function args)))
- (buttercup--spy-add-call
+ (buttercup--spy-calls-add
this-spy-function
(make-spy-context :args args
:return-value return-value
@@ -451,47 +451,49 @@ KEYWORD can have one of the following values:
(append buttercup--cleanup-forms
(list function)))))
-(defun buttercup--spy-add-call (spy context)
+(defun spy-calls-all (spy)
+ "Return the contexts of calls to SPY."
+ (gethash (symbol-function spy)
+ buttercup--spy-contexts))
+
+(defun buttercup--spy-calls-add (spy-function context)
"Add CONTEXT to the recorded calls to SPY."
- (puthash spy
- (append (buttercup--spy-calls spy)
+ (puthash spy-function
+ (append (gethash spy-function
+ buttercup--spy-contexts)
(list context))
- buttercup--spy-calls))
+ buttercup--spy-contexts))
-(defun buttercup--spy-calls (spy)
- "Return the contexts of calls to SPY."
- (gethash spy buttercup--spy-calls))
+(defun spy-calls-reset (spy)
+ "Reset SPY, removing all recorded calls."
+ (puthash (symbol-function spy)
+ nil
+ buttercup--spy-contexts))
(buttercup-define-matcher :to-have-been-called (spy)
- (let ((spy (if (symbolp spy)
- (symbol-function spy)
- spy)))
- (if (buttercup--spy-calls spy)
- t
- nil)))
+ (if (spy-calls-all spy)
+ t
+ nil))
(buttercup-define-matcher :to-have-been-called-with (spy &rest args)
- (let* ((spy (if (symbolp spy)
- (symbol-function spy)
- spy))
- (calls (mapcar 'spy-context-args (buttercup--spy-calls spy))))
+ (let* ((calls (mapcar 'spy-context-args (spy-calls-all spy))))
(if (member args calls)
t
nil)))
(defun spy-calls-any (spy)
"Return t iff SPY has been called at all, nil otherwise."
- (if (buttercup--spy-calls (symbol-function spy))
+ (if (spy-calls-all spy)
t
nil))
(defun spy-calls-count (spy)
"Return the number of times SPY has been called so far."
- (length (buttercup--spy-calls (symbol-function spy))))
+ (length (spy-calls-all spy)))
(defun spy-calls-args-for (spy index)
"Return the context of the INDEXth call to SPY."
- (let ((context (elt (buttercup--spy-calls (symbol-function spy))
+ (let ((context (elt (spy-calls-all spy)
index)))
(if context
(spy-context-args context)
@@ -499,25 +501,15 @@ KEYWORD can have one of the following values:
(defun spy-calls-all-args (spy)
"Return the arguments to all calls to SPY."
- (mapcar 'spy-context-args (buttercup--spy-calls (symbol-function spy))))
-
-(defun spy-calls-all (spy)
- "Return the contexts of all calls to SPY."
- (buttercup--spy-calls (symbol-function spy)))
+ (mapcar 'spy-context-args (spy-calls-all spy)))
(defun spy-calls-most-recent (spy)
"Return the context of the most recent call to SPY."
- (car (last (buttercup--spy-calls (symbol-function spy)))))
+ (car (last (spy-calls-all spy))))
(defun spy-calls-first (spy)
"Return the context of the first call to SPY."
- (car (buttercup--spy-calls (symbol-function spy))))
-
-(defun spy-calls-reset (spy)
- "Reset SPY, removing all recorded calls."
- (puthash (symbol-function spy)
- nil
- buttercup--spy-calls))
+ (car (spy-calls-all spy)))
;; (let* ((buttercup--descriptions (cons description
;; buttercup--descriptions))
- [nongnu] elpa/buttercup 36522b9 006/340: Add .travis.yml, (continued)
- [nongnu] elpa/buttercup 36522b9 006/340: Add .travis.yml, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f44e65d 004/340: Unit tests for define-matcher and apply-matcher., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d3cd12a 019/340: Tests for the buttercup-describe function, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3772ad5 014/340: Use eval-region instead of eval-buffer., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8aa87c8 026/340: Spy :and-call-through, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 683614d 018/340: Tests for the describe macro., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0221830 023/340: Remove setup and teardown from ROADMAP.md., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 695e444 016/340: buttercup-markdown-runner: Use setq, not setq-local., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7526198 029/340: Spies: :and-throw-error, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 77d1dac 017/340: Test buttercup-suite-add-child., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c1abc2a 033/340: Refactoring of spy context accessors.,
ELPA Syncer <=
- [nongnu] elpa/buttercup f314737 035/340: ROADMAP.md: Remove spies section, as it is done., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4bd24e7 037/340: ROADMAP cleanup., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 55b87ec 039/340: Removed ROADMAP.md. This is now tracked in issues., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 993ddda 040/340: Add .gitignore, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1dcd2cd 041/340: Prepare release, add bumpversion and pkg.el, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f046eef 042/340: Bump version: 0.1 → 1.0, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 537b729 044/340: Merge pull request #6 from myeffort/master, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bcaa087 046/340: Add buttercup executable to run buttercup tests more easily., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7250873 047/340: Rename patch to minor in bumpversion.cfg, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 13c463a 050/340: Add more extensive usage instructions to the README., ELPA Syncer, 2021/12/16