|
| 1 | +;;; clojure-ts-mode-config-test.el --- Clojure TS Mode: configuration 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 | +;; Tests for clojure-ts-mode configuration options (defcustom variables). |
| 23 | + |
| 24 | +;;; Code: |
| 25 | + |
| 26 | +(require 'clojure-ts-mode) |
| 27 | +(require 'buttercup) |
| 28 | +(require 'test-helper "test/test-helper") |
| 29 | + |
| 30 | +;;;; clojure-ts-toplevel-inside-comment-form |
| 31 | + |
| 32 | +(describe "clojure-ts-toplevel-inside-comment-form" |
| 33 | + (before-all |
| 34 | + (unless (treesit-language-available-p 'clojure) |
| 35 | + (signal 'buttercup-pending "tree-sitter Clojure grammar not available"))) |
| 36 | + |
| 37 | + (it "should treat the comment form as a defun when nil (default)" |
| 38 | + (with-clojure-ts-buffer "(comment\n (defn foo [] 1)\n (defn bar [] 2))" |
| 39 | + ;; Point inside the comment form |
| 40 | + (goto-char 15) |
| 41 | + (let ((node (treesit-defun-at-point))) |
| 42 | + ;; The defun-at-point should be the comment form |
| 43 | + (expect node :not :to-be nil) |
| 44 | + (expect (string-prefix-p "(comment" (treesit-node-text node)) |
| 45 | + :to-be-truthy)))) |
| 46 | + |
| 47 | + (it "should navigate to inner defns when non-nil" |
| 48 | + (with-clojure-ts-buffer "(comment\n (defn foo [] 1)\n (defn bar [] 2))" |
| 49 | + (setq-local clojure-ts-toplevel-inside-comment-form t) |
| 50 | + ;; Point inside the comment form |
| 51 | + (goto-char 15) |
| 52 | + (let ((node (treesit-defun-at-point))) |
| 53 | + ;; The defun-at-point should be the inner defn, not the comment |
| 54 | + (expect node :not :to-be nil) |
| 55 | + (expect (string-prefix-p "(defn foo" (treesit-node-text node)) |
| 56 | + :to-be-truthy))))) |
| 57 | + |
| 58 | +;;;; clojure-ts-docstring-fill-column |
| 59 | + |
| 60 | +(describe "clojure-ts-docstring-fill-column" |
| 61 | + (it "should use the custom fill column when filling docstrings" |
| 62 | + (with-clojure-ts-buffer "(defn foo |
| 63 | + \"This is a short docstring.\" |
| 64 | + [])" |
| 65 | + (let ((clojure-ts-docstring-fill-column 20)) |
| 66 | + (goto-char (point-min)) |
| 67 | + (search-forward "This") |
| 68 | + (fill-paragraph) |
| 69 | + (expect (buffer-substring-no-properties (point-min) (point-max)) |
| 70 | + :to-equal "(defn foo |
| 71 | + \"This is a short |
| 72 | + docstring.\" |
| 73 | + [])")))) |
| 74 | + |
| 75 | + (it "should not affect comment filling" |
| 76 | + (with-clojure-ts-buffer ";; This is a comment that should not be affected by the docstring fill column setting." |
| 77 | + (let ((clojure-ts-docstring-fill-column 10) |
| 78 | + (fill-column 70)) |
| 79 | + (goto-char (point-min)) |
| 80 | + (fill-paragraph) |
| 81 | + ;; Comment wraps at fill-column (70), not docstring-fill-column (10) |
| 82 | + (expect (buffer-substring-no-properties (point-min) (point-max)) |
| 83 | + :to-equal ";; This is a comment that should not be affected by the docstring fill |
| 84 | +;; column setting."))))) |
| 85 | + |
| 86 | +;;;; clojure-ts-docstring-fill-prefix-width |
| 87 | + |
| 88 | +(describe "clojure-ts-docstring-fill-prefix-width" |
| 89 | + (it "should use custom fill prefix width when filling docstrings" |
| 90 | + (with-clojure-ts-buffer "(defn foo |
| 91 | + \"This is a short docstring.\" |
| 92 | + [])" |
| 93 | + (let ((clojure-ts-docstring-fill-column 20) |
| 94 | + (clojure-ts-docstring-fill-prefix-width 4)) |
| 95 | + (goto-char (point-min)) |
| 96 | + (search-forward "This") |
| 97 | + (fill-paragraph) |
| 98 | + ;; Continuation lines should be indented with 4 spaces |
| 99 | + (expect (buffer-substring-no-properties (point-min) (point-max)) |
| 100 | + :to-equal "(defn foo |
| 101 | + \"This is a short |
| 102 | + docstring.\" |
| 103 | + [])")))) |
| 104 | + |
| 105 | + (it "should default to 2 spaces for fill prefix" |
| 106 | + (with-clojure-ts-buffer "(defn foo |
| 107 | + \"This is a short docstring.\" |
| 108 | + [])" |
| 109 | + (let ((clojure-ts-docstring-fill-column 20)) |
| 110 | + (goto-char (point-min)) |
| 111 | + (search-forward "This") |
| 112 | + (fill-paragraph) |
| 113 | + ;; Default: continuation lines indented with 2 spaces |
| 114 | + (expect (buffer-substring-no-properties (point-min) (point-max)) |
| 115 | + :to-equal "(defn foo |
| 116 | + \"This is a short |
| 117 | + docstring.\" |
| 118 | + [])"))))) |
| 119 | + |
| 120 | +;;;; clojure-ts-thread-all-but-last |
| 121 | + |
| 122 | +(describe "clojure-ts-thread-all-but-last" |
| 123 | + (it "should thread all expressions by default" |
| 124 | + (with-clojure-ts-buffer "(map inc (filter even? coll))" |
| 125 | + (goto-char (point-min)) |
| 126 | + (clojure-ts-thread-last-all nil) |
| 127 | + (expect (buffer-string) |
| 128 | + :to-equal "(->> coll\n (filter even?)\n (map inc))"))) |
| 129 | + |
| 130 | + (it "should leave last expression unthreaded when set to t" |
| 131 | + (with-clojure-ts-buffer "(map inc (filter even? coll))" |
| 132 | + (let ((clojure-ts-thread-all-but-last t)) |
| 133 | + (goto-char (point-min)) |
| 134 | + (clojure-ts-thread-last-all nil)) |
| 135 | + (expect (buffer-string) |
| 136 | + :to-equal "(->> (filter even? coll)\n (map inc))"))) |
| 137 | + |
| 138 | + (it "should apply to thread-first-all as well" |
| 139 | + (with-clojure-ts-buffer "(assoc (merge {} {:a 1}) :b 2)" |
| 140 | + (let ((clojure-ts-thread-all-but-last t)) |
| 141 | + (goto-char (point-min)) |
| 142 | + (clojure-ts-thread-first-all nil)) |
| 143 | + (expect (buffer-string) |
| 144 | + :to-equal "(-> (merge {} {:a 1})\n (assoc :b 2))")))) |
| 145 | + |
| 146 | +;;; clojure-ts-mode-config-test.el ends here |
0 commit comments