Skip to content

Commit ccce18a

Browse files
p4v4nbbatsov
authored andcommitted
Import a couple of test-helpers from clojure-mode
1 parent f3d9e98 commit ccce18a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/utils/test-helper.el

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;;; test-helper.el --- Clojure TS Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2022-2024 Danny Freeman
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; Non-interactive test suite setup.
23+
24+
;;; Code:
25+
26+
(defmacro with-clojure-ts-buffer (text &rest body)
27+
"Create a temporary buffer, insert TEXT,switch to clojure-ts-mode.
28+
And evaluate BODY."
29+
(declare (indent 1))
30+
`(with-temp-buffer
31+
(erase-buffer)
32+
(insert ,text)
33+
(clojure-ts-mode)
34+
,@body))
35+
36+
(defmacro with-clojure-ts-buffer-point (text &rest body)
37+
"Run BODY in a temporary clojure buffer with TEXT.
38+
39+
TEXT is a string with a | indicating where point is. The | will be erased
40+
and point left there."
41+
(declare (indent 2))
42+
`(progn
43+
(with-clojure-ts-buffer ,text
44+
(goto-char (point-min))
45+
(re-search-forward "|")
46+
(delete-char -1)
47+
,@body)))
48+
49+
(provide 'test-helper)
50+
;;; test-helper.el ends here

0 commit comments

Comments
 (0)