Skip to content

Commit 762af3d

Browse files
committed
Add integration test suite
Verify font-lock and imenu against real sample files to catch regressions that unit tests on small snippets might miss.
1 parent e5f5493 commit 762af3d

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
;;; clojure-ts-mode-integration-test.el --- Clojure TS Mode: integration test suite -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2025-2026 Bozhidar Batsov
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+
;; Integration tests that load sample resource files and verify that
23+
;; font-lock and imenu work correctly end-to-end.
24+
25+
;;; Code:
26+
27+
(require 'clojure-ts-mode)
28+
(require 'buttercup)
29+
(require 'imenu)
30+
(require 'test-helper "test/test-helper")
31+
32+
(describe "integration: font-lock on sample files"
33+
(before-all
34+
(unless (treesit-language-available-p 'clojure)
35+
(signal 'buttercup-pending "tree-sitter Clojure grammar not available")))
36+
37+
(it "applies expected font-lock faces to indentation.clj"
38+
(let ((file (clojure-ts-test--resource-file "indentation.clj")))
39+
(with-temp-buffer
40+
(insert-file-contents file)
41+
(let ((treesit-font-lock-level 4))
42+
(clojure-ts-mode))
43+
(font-lock-ensure)
44+
;; Check that "defn" keyword is fontified
45+
(goto-char (point-min))
46+
(search-forward "(defn f")
47+
(expect (get-text-property (1+ (match-beginning 0)) 'face)
48+
:to-equal 'font-lock-keyword-face)
49+
;; Check that a docstring is fontified
50+
(goto-char (point-min))
51+
(search-forward "\"Docstring")
52+
(expect (get-text-property (match-beginning 0) 'face)
53+
:to-equal 'font-lock-doc-face)
54+
;; Check that a comment is fontified
55+
(goto-char (point-min))
56+
(search-forward ";; double")
57+
(expect (get-text-property (match-beginning 0) 'face)
58+
:to-equal 'font-lock-comment-face))))
59+
60+
(it "applies expected font-lock faces to test.clj"
61+
(let ((file (clojure-ts-test--resource-file "test.clj")))
62+
(with-temp-buffer
63+
(insert-file-contents file)
64+
(let ((treesit-font-lock-level 3))
65+
(clojure-ts-mode))
66+
(font-lock-ensure)
67+
;; Check that "ns" is fontified
68+
(goto-char (point-min))
69+
(search-forward "(ns ")
70+
(expect (get-text-property (1+ (match-beginning 0)) 'face)
71+
:to-equal 'font-lock-keyword-face)))))
72+
73+
(describe "integration: imenu on sample files"
74+
(before-all
75+
(unless (treesit-language-available-p 'clojure)
76+
(signal 'buttercup-pending "tree-sitter Clojure grammar not available")))
77+
78+
(it "builds imenu index from indentation.clj"
79+
(let ((file (clojure-ts-test--resource-file "indentation.clj")))
80+
(with-temp-buffer
81+
(insert-file-contents file)
82+
(clojure-ts-mode)
83+
(let ((index (imenu--make-index-alist)))
84+
;; Should have Function and Variable categories
85+
(expect (assoc "Function" index) :not :to-be nil)
86+
(expect (assoc "Variable" index) :not :to-be nil)))))
87+
88+
(it "builds imenu index from refactoring.clj"
89+
(let ((file (clojure-ts-test--resource-file "refactoring.clj")))
90+
(with-temp-buffer
91+
(insert-file-contents file)
92+
(clojure-ts-mode)
93+
(let* ((index (imenu--make-index-alist))
94+
(flatten-index (imenu--flatten-index-alist index t)))
95+
;; Should find the namespace
96+
(expect (assoc "Namespace:refactoring" flatten-index) :not :to-be nil))))))
97+
98+
;;; clojure-ts-mode-integration-test.el ends here

0 commit comments

Comments
 (0)