Skip to content

Commit 40c9c76

Browse files
committed
Add tests for clojure-get-indent-function
Verify that the custom indent spec lookup hook works: - A custom function can provide specs for unknown forms - When the custom function returns nil, built-in specs still apply
1 parent 5c42d77 commit 40c9c76

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/clojure-mode-indentation-test.el

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,27 @@ x
13111311
(indent-region (point-min) (point-max))
13121312
(expect (buffer-string) :to-equal "\n(defn foo\n [x]\n x)")))))
13131313

1314+
(describe "clojure-get-indent-function"
1315+
(it "should use custom function to look up indent specs"
1316+
(let ((clojure-get-indent-function
1317+
(lambda (name)
1318+
(when (string= name "my-custom-macro")
1319+
1))))
1320+
;; my-custom-macro has no built-in spec, but our custom function
1321+
;; provides spec 1 (one special arg, then body).
1322+
(with-clojure-buffer "\n(my-custom-macro binding\nbody)"
1323+
(indent-region (point-min) (point-max))
1324+
(expect (buffer-string) :to-equal "\n(my-custom-macro binding\n body)"))))
1325+
1326+
(it "should fall back to built-in specs when custom function returns nil"
1327+
(let ((clojure-get-indent-function
1328+
(lambda (_name) nil)))
1329+
;; let has a built-in spec, and the custom function returns nil,
1330+
;; so the built-in spec should still apply.
1331+
(with-clojure-buffer "\n(let [x 1]\nx)"
1332+
(indent-region (point-min) (point-max))
1333+
(expect (buffer-string) :to-equal "\n(let [x 1]\n x)")))))
1334+
13141335
(provide 'clojure-mode-indentation-test)
13151336

13161337
;;; clojure-mode-indentation-test.el ends here

0 commit comments

Comments
 (0)