Skip to content

Commit c259d30

Browse files
committed
Move over remaining test utils from the clojure-mode test-helper
1 parent b3817dc commit c259d30

File tree

2 files changed

+52
-103
lines changed

2 files changed

+52
-103
lines changed

test/test-helper.el

+52
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,56 @@ attention to case differences."
5555
(let ((case-fold-search ignore-case))
5656
(string-match-p (regexp-quote needle) s)))
5757

58+
(defmacro when-refactoring-it (description before after &rest body)
59+
"Return a buttercup spec.
60+
61+
Insert BEFORE into a buffer, evaluate BODY and compare the resulting buffer to
62+
AFTER.
63+
64+
BODY should contain the refactoring that transforms BEFORE into AFTER.
65+
66+
DESCRIPTION is the description of the spec."
67+
(declare (indent 1))
68+
`(it ,description
69+
(with-clojure-ts-buffer ,before
70+
,@body
71+
(expect (buffer-string) :to-equal ,after))))
72+
73+
(defmacro when-refactoring-with-point-it (description before after &rest body)
74+
"Return a buttercup spec.
75+
76+
Like when-refactor-it but also checks whether point is moved to the expected
77+
position.
78+
79+
BEFORE is the buffer string before refactoring, where a pipe (|) represents
80+
point.
81+
82+
AFTER is the expected buffer string after refactoring, where a pipe (|)
83+
represents the expected position of point.
84+
85+
DESCRIPTION is a string with the description of the spec."
86+
(declare (indent 1))
87+
`(it ,description
88+
(let* ((after ,after)
89+
(expected-cursor-pos (1+ (clojure-ts--s-index-of "|" after)))
90+
(expected-state (delete ?| after)))
91+
(with-clojure-ts-buffer ,before
92+
(goto-char (point-min))
93+
(search-forward "|")
94+
(delete-char -1)
95+
,@body
96+
(expect (buffer-string) :to-equal expected-state)
97+
(expect (point) :to-equal expected-cursor-pos)))))
98+
99+
100+
;; https://emacs.stackexchange.com/a/55031
101+
(defmacro with-temp-dir (temp-dir &rest body)
102+
"Create a temporary directory and bind its to TEMP-DIR while evaluating BODY.
103+
Removes the temp directory at the end of evaluation."
104+
`(let ((,temp-dir (make-temp-file "" t)))
105+
(unwind-protect
106+
(progn
107+
,@body)
108+
(delete-directory ,temp-dir t))))
109+
58110
;;; test-helper.el ends here

utils/test-helper.el

-103
This file was deleted.

0 commit comments

Comments
 (0)