Conform unit test macros to naming convention

This commit is contained in:
Henrik Lissner 2018-03-27 02:52:30 -04:00
parent 2364e97285
commit 1f9576a59a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 14 additions and 14 deletions

View file

@ -71,7 +71,7 @@ If neither is available, run all tests in all enabled modules."
(setq plist (reverse plist)) (setq plist (reverse plist))
(when-let* ((modes (doom-enlist (plist-get plist :minor-mode)))) (when-let* ((modes (doom-enlist (plist-get plist :minor-mode))))
(dolist (mode modes) (dolist (mode modes)
(setq body `((with-minor-mode!! ,mode ,@body))))) (setq body `((with-minor-mode! ,mode ,@body)))))
(when-let* ((before (plist-get plist :before))) (when-let* ((before (plist-get plist :before)))
(setq body `(,@before ,@body))) (setq body `(,@before ,@body)))
(when-let* ((after (plist-get plist :after))) (when-let* ((after (plist-get plist :after)))
@ -91,7 +91,7 @@ If neither is available, run all tests in all enabled modules."
(save-window-excursion (save-window-excursion
,@body))))))) ,@body)))))))
(defmacro should-buffer!! (initial expected &rest body) (defmacro should-buffer! (initial expected &rest body)
"Test that a buffer with INITIAL text, run BODY, then test it against EXPECTED. "Test that a buffer with INITIAL text, run BODY, then test it against EXPECTED.
INITIAL will recognize cursor markers in the form {[0-9]}. A {0} marker marks INITIAL will recognize cursor markers in the form {[0-9]}. A {0} marker marks
@ -119,7 +119,7 @@ against."
(lambda (m1 m2) (< (marker-position m1) (lambda (m1 m2) (< (marker-position m1)
(marker-position m2)))) (marker-position m2))))
(when (equal (caar marker-list) "0") (when (equal (caar marker-list) "0")
(goto-char!! 0))) (goto-char! 0)))
,@body ,@body
(let ((result-text (buffer-substring-no-properties (point-min) (point-max))) (let ((result-text (buffer-substring-no-properties (point-min) (point-max)))
(point (point)) (point (point))
@ -137,27 +137,27 @@ against."
(should (equal expected-text result-text)) (should (equal expected-text result-text))
(should same-point))))))) (should same-point)))))))
(defmacro goto-char!! (index) (defmacro goto-char! (index)
"Meant to be used with `should-buffer!!'. Will move the cursor to one of the "Meant to be used with `should-buffer!'. Will move the cursor to one of the
cursor markers. e.g. Go to marker {2} with (goto-char!! 2)." cursor markers. e.g. Go to marker {2} with (goto-char! 2)."
`(goto-char (point!! ,index))) `(goto-char (point! ,index)))
(defmacro point!! (index) (defmacro point! (index)
"Meant to be used with `should-buffer!!'. Returns the position of a cursor "Meant to be used with `should-buffer!'. Returns the position of a cursor
marker. e.g. {2} can be retrieved with (point!! 2)." marker. e.g. {2} can be retrieved with (point! 2)."
`(cdr (assoc ,(cond ((numberp index) (number-to-string index)) `(cdr (assoc ,(cond ((numberp index) (number-to-string index))
((symbolp index) (symbol-name index)) ((symbolp index) (symbol-name index))
((stringp index) index)) ((stringp index) index))
marker-list))) marker-list)))
(defmacro with-minor-mode!! (mode &rest body) (defmacro with-minor-mode! (mode &rest body)
"Activate a minor mode while in BODY, deactivating it after." "Activate a minor mode while in BODY, deactivating it after."
(declare (indent defun)) (declare (indent defun))
`(progn (,mode +1) `(progn (,mode +1)
,@body ,@body
(,mode -1))) (,mode -1)))
(defmacro let-advice!! (binds &rest body) (defmacro let-advice! (binds &rest body)
"Temporarily bind advice in BINDS while in BODY. "Temporarily bind advice in BINDS while in BODY.
e.g. (old-fn :before advice-fn) e.g. (old-fn :before advice-fn)

View file

@ -9,7 +9,7 @@ affects your Emacs packages)."
(other ,dest)) (other ,dest))
(with-temp-file it (with-temp-file it
(insert "Hello world")) (insert "Hello world"))
(with-minor-mode!! projectile-mode (with-minor-mode! projectile-mode
(unwind-protect (unwind-protect
(progn (progn
(should (file-exists-p it)) (should (file-exists-p it))

View file

@ -4,7 +4,7 @@
(require! :lang org) (require! :lang org)
(defmacro should-org-buffer!! (source expected &rest body) (defmacro should-org-buffer!! (source expected &rest body)
`(should-buffer!! ,source ,expected `(should-buffer! ,source ,expected
(org-mode) (org-mode)
,@body)) ,@body))