Skip to content

Commit

Permalink
convert to hashtables expecting a list type alist
Browse files Browse the repository at this point in the history
  • Loading branch information
nicferrier committed Jun 7, 2012
1 parent 967c23a commit 330b517
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions fakir.el
Expand Up @@ -4,7 +4,7 @@
;; Author: Nic Ferrier <nferrier@ferrier.me.uk> ;; Author: Nic Ferrier <nferrier@ferrier.me.uk>
;; Maintainer: Nic Ferrier <nferrier@ferrier.me.uk> ;; Maintainer: Nic Ferrier <nferrier@ferrier.me.uk>
;; Created: 17th March 2012 ;; Created: 17th March 2012
;; Version: 0.0.6 ;; Version: 0.0.7
;; Keywords: lisp, tools ;; Keywords: lisp, tools


;; This file is NOT part of GNU Emacs. ;; This file is NOT part of GNU Emacs.
Expand Down Expand Up @@ -66,9 +66,11 @@ The ALIST looks like a let-list."
(list (list :fakir-mock-process t)) (list (list :fakir-mock-process t))
alist) alist)
do do
(if (and f (listp f)) (cond
(puthash (car f) (cadr f) bindings) ((and f (listp f))
(puthash f nil bindings))) (puthash (car f) (cadr f) bindings))
(t
(puthash f nil bindings))))
bindings)) bindings))


(ert-deftest fakir--make-hash-table () (ert-deftest fakir--make-hash-table ()
Expand Down Expand Up @@ -113,7 +115,13 @@ We return what the BODY returned."
(pvbuf (make-symbol "buf")) (pvbuf (make-symbol "buf"))
(result (make-symbol "result"))) (result (make-symbol "result")))
`(let `(let
((,pvvar (fakir--make-hash-table (quote ,process-bindings))) ((,pvvar
(fakir--make-hash-table
(list ,@(loop for p in process-bindings
collect
(if (and p (listp p))
(list 'list `(quote ,(car p)) (cadr p))
(list 'cons `,p nil))))))
;; For assigning the result of the body ;; For assigning the result of the body
,result ,result
;; Dummy buffer variable for the process - we fill this in ;; Dummy buffer variable for the process - we fill this in
Expand Down Expand Up @@ -166,8 +174,7 @@ We return what the BODY returned."
(set-process-buffer (set-process-buffer
(proc buffer) (proc buffer)
(get-or-create-pvbuf proc buffer))) (get-or-create-pvbuf proc buffer)))
(setq ,result (progn ,@body)) (setq ,result (progn ,@body)))
)
;; Now clean up ;; Now clean up
(when (bufferp ,pvbuf) (when (bufferp ,pvbuf)
(with-current-buffer ,pvbuf (with-current-buffer ,pvbuf
Expand All @@ -178,19 +185,21 @@ We return what the BODY returned."


(defun fakir-test-mock-process () (defun fakir-test-mock-process ()
"A very quick function to test mocking process macro." "A very quick function to test mocking process macro."
(fakir-mock-process (let ((somevalue 30))
((a 20) (fakir-mock-process
(:somevar 15)) ((a 20)
(let ((z 10)) (:somevar 15)
(let ((a "my string!!!")) (:othervar somevalue))
(setq a (process-get t :somevar)) (let ((z 10))
a)))) (let ((a "my string!!!"))
(setq a (process-get t :somevar))
(list a (process-get t :othervar)))))))


(ert-deftest fakir-mock-process () (ert-deftest fakir-mock-process ()
"Test mock process." "Test mock process."
:tags '(unit) :tags '(unit)
(let ((x (fakir-test-mock-process))) (let ((x (fakir-test-mock-process)))
(should (equal 15 x)))) (should (equal '(15 30) x))))




;; Time utils ;; Time utils
Expand Down

0 comments on commit 330b517

Please sign in to comment.