|
3 | 3 | (require 'ert) |
4 | 4 | (require 'hack-mode) |
5 | 5 |
|
| 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 | + |
6 | 24 | (defun hack--search-up-to (char) |
7 | 25 | "Search forward for the next occurrence of CHAR, and put point before it." |
8 | 26 | (search-forward char) |
9 | 27 | (backward-char)) |
10 | 28 |
|
11 | 29 | (ert-deftest hack-fill-paragraph-comment () |
12 | 30 | "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" |
18 | 32 | (fill-paragraph) |
19 | 33 | (should |
20 | 34 | (equal |
|
24 | 38 |
|
25 | 39 | (ert-deftest hack-fill-paragraph-docblock () |
26 | 40 | "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 */" |
31 | 42 | (forward-line) |
32 | | - |
33 | 43 | (fill-paragraph) |
34 | 44 | (should |
35 | 45 | (equal |
@@ -279,24 +289,6 @@ function stuff(): int { |
279 | 289 | (indent-region (point-min) (point-max)) |
280 | 290 | (should (string= (buffer-string) src))))) |
281 | 291 |
|
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 | | - |
300 | 292 | (ert-deftest hack-syntax-angle-bracket-for-type () |
301 | 293 | "Match angle brackets in type parameters." |
302 | 294 | (with-hack-buffer "function foo(vec<int> $_): void {}" |
|
0 commit comments