Skip to content

Commit bf7ec9f

Browse files
committed
Use with-hack-buffer in more tests
1 parent 4c1c2b0 commit bf7ec9f

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

test/hack-unit-test.el

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
(require 'ert)
44
(require 'hack-mode)
55

6+
(defmacro with-hack-buffer (src &rest body)
7+
"Insert SRC in a temporary `hack-mode' buffer, apply syntax highlighting,
8+
then run BODY."
9+
(declare (indent 1) (debug t))
10+
`(with-temp-buffer
11+
(insert ,src)
12+
(goto-char (point-min))
13+
;; Activate hack-mode, but don't run any hooks. This doesn't
14+
;; matter on Travis, but is defensive when running tests in the
15+
;; current Emacs instance.
16+
(delay-mode-hooks (hack-mode))
17+
;; Ensure we've syntax-highlighted the whole buffer.
18+
(if (fboundp 'font-lock-ensure)
19+
(font-lock-ensure)
20+
(with-no-warnings
21+
(font-lock-fontify-buffer)))
22+
,@body))
23+
624
(defun hack--search-up-to (char)
725
"Search forward for the next occurrence of CHAR, and put point before it."
826
(search-forward char)
927
(backward-char))
1028

1129
(ert-deftest hack-fill-paragraph-comment ()
1230
"Comments with // should be filled correctly."
13-
(with-temp-buffer
14-
(hack-mode)
15-
(insert "// foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz")
16-
(goto-char (point-min))
17-
31+
(with-hack-buffer "// foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz foo bar baaaaaaaz"
1832
(fill-paragraph)
1933
(should
2034
(equal
@@ -24,12 +38,8 @@
2438

2539
(ert-deftest hack-fill-paragraph-docblock ()
2640
"Comments with /* should be filled correctly."
27-
(with-temp-buffer
28-
(hack-mode)
29-
(insert "/**\n * Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing\n *\n * This runs very quickly\n */")
30-
(goto-char (point-min))
41+
(with-hack-buffer "/**\n * Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing Thing\n *\n * This runs very quickly\n */"
3142
(forward-line)
32-
3343
(fill-paragraph)
3444
(should
3545
(equal
@@ -279,24 +289,6 @@ function stuff(): int {
279289
(indent-region (point-min) (point-max))
280290
(should (string= (buffer-string) src)))))
281291

282-
(defmacro with-hack-buffer (src &rest body)
283-
"Insert SRC in a temporary `hack-mode' buffer, apply syntax highlighting,
284-
then run BODY."
285-
(declare (indent 1) (debug t))
286-
`(with-temp-buffer
287-
(insert ,src)
288-
(goto-char (point-min))
289-
;; Activate hack-mode, but don't run any hooks. This doesn't
290-
;; matter on Travis, but is defensive when running tests in the
291-
;; current Emacs instance.
292-
(delay-mode-hooks (hack-mode))
293-
;; Ensure we've syntax-highlighted the whole buffer.
294-
(if (fboundp 'font-lock-ensure)
295-
(font-lock-ensure)
296-
(with-no-warnings
297-
(font-lock-fontify-buffer)))
298-
,@body))
299-
300292
(ert-deftest hack-syntax-angle-bracket-for-type ()
301293
"Match angle brackets in type parameters."
302294
(with-hack-buffer "function foo(vec<int> $_): void {}"

0 commit comments

Comments
 (0)