|
| 1 | +;;; cider-find-ts-tests.el --- -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2025 Roman Rudakov |
| 4 | + |
| 5 | +;; Author: Roman Rudakov <[email protected]> |
| 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 | +;; This is part of CIDER |
| 23 | + |
| 24 | +;;; Code: |
| 25 | + |
| 26 | +(require 'buttercup) |
| 27 | +(require 'cider-find) |
| 28 | + |
| 29 | +(describe "cider--find-keyword-loc (TreeSitter)" |
| 30 | + (it "finds the given keyword, discarding false positives" |
| 31 | + (with-clojure-ts-buffer "(ns some.ns) |
| 32 | +;; ::foo |
| 33 | +\"::foo\" |
| 34 | +#_::foo |
| 35 | +::foobar |
| 36 | +\" |
| 37 | +::foo |
| 38 | +\" |
| 39 | +::foo |
| 40 | +more |
| 41 | +stuff" |
| 42 | + (let* ((sample-buffer (current-buffer))) |
| 43 | + (spy-on 'cider-ensure-connected :and-return-value t) |
| 44 | + (spy-on 'cider-sync-request:ns-path :and-call-fake (lambda (kw-ns _) |
| 45 | + kw-ns)) |
| 46 | + (spy-on 'cider-resolve-alias :and-call-fake (lambda (_ns ns-qualifier) |
| 47 | + ns-qualifier)) |
| 48 | + (spy-on 'cider-find-file :and-call-fake (lambda (kw-ns) |
| 49 | + (when (equal kw-ns "some.ns") |
| 50 | + sample-buffer))) |
| 51 | + |
| 52 | + (nrepl-dbind-response (cider--find-keyword-loc "::some.ns/foo") (dest dest-point) |
| 53 | + (expect dest-point :to-equal 63) |
| 54 | + (with-current-buffer dest |
| 55 | + (goto-char dest-point) |
| 56 | + ;; important - ensure that we're looking at ::foo and not ::foobar: |
| 57 | + (expect (cider-symbol-at-point 'look-back) :to-equal "::foo"))) |
| 58 | + |
| 59 | + (nrepl-dbind-response (cider--find-keyword-loc "::foo") (dest dest-point) |
| 60 | + (expect dest-point :to-equal 63) |
| 61 | + (with-current-buffer dest |
| 62 | + (goto-char dest-point) |
| 63 | + ;; important - ensure that we're looking at ::foo and not ::foobar: |
| 64 | + (expect (cider-symbol-at-point 'look-back) :to-equal "::foo"))) |
| 65 | + |
| 66 | + (nrepl-dbind-response (cider--find-keyword-loc ":some.ns/foo") (dest dest-point) |
| 67 | + (expect dest-point :to-equal 63) |
| 68 | + (with-current-buffer dest |
| 69 | + (goto-char dest-point) |
| 70 | + ;; important - ensure that we're looking at ::foo and not ::foobar: |
| 71 | + (expect (cider-symbol-at-point 'look-back) :to-equal "::foo"))) |
| 72 | + |
| 73 | + (nrepl-dbind-response (cider--find-keyword-loc "::some.ns/bar") (dest dest-point) |
| 74 | + (expect dest-point :to-equal nil)) |
| 75 | + |
| 76 | + (nrepl-dbind-response (cider--find-keyword-loc ":some.ns/bar") (dest dest-point) |
| 77 | + (expect dest-point :to-equal nil)) |
| 78 | + |
| 79 | + (expect (cider--find-keyword-loc ":foo") :to-throw 'user-error) |
| 80 | + |
| 81 | + (nrepl-dbind-response (cider--find-keyword-loc ":unrelated/foo") (dest dest-point) |
| 82 | + (expect dest-point :to-equal nil)) |
| 83 | + |
| 84 | + (nrepl-dbind-response (cider--find-keyword-loc "::unrelated/foo") (dest dest-point) |
| 85 | + (expect dest-point :to-equal nil)))))) |
| 86 | + |
| 87 | +(provide 'cider-find-ts-tests) |
| 88 | +;;; cider-find-ts-tests.el ends here |
0 commit comments