aboutsummaryrefslogtreecommitdiff
path: root/tests/test-prog-general--pin-go-treesit-revision.el
blob: 42845b4f684ed9a73e5413fcfe05cdae3786b53d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;;; test-prog-general--pin-go-treesit-revision.el --- Go grammar pinning -*- lexical-binding: t; -*-

;;; Commentary:
;; The treesit-auto Go recipe is pinned for compatibility with Emacs 30.2.
;; Keep the mutation independent of cl-defstruct's compile-time setter
;; expansion: prog-general is loaded before treesit-auto defines that setter
;; during a normal startup.

;;; Code:

(require 'ert)
(require 'cl-lib)

;; Deliberately put `revision' at a different offset from treesit-auto's real
;; struct.  The production helper must discover the slot rather than hard-code
;; the package's current vector layout.
(cl-defstruct treesit-auto-recipe lang revision url)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'prog-general)

(ert-deftest test-prog-general-pin-go-treesit-revision-updates-go ()
  "Normal: the Go recipe receives the supported grammar revision."
  (let* ((go (make-treesit-auto-recipe
              :lang 'go :revision "main" :url "https://example.test/go"))
         (python (make-treesit-auto-recipe
                  :lang 'python :revision "main"
                  :url "https://example.test/python")))
    (cj/treesit-auto-pin-go-revision (list python go))
    (should (equal (treesit-auto-recipe-revision go) "v0.19.1"))
    (should (equal (treesit-auto-recipe-revision python) "main"))))

(ert-deftest test-prog-general-pin-go-treesit-revision-no-go-is-no-op ()
  "Boundary: a recipe list without Go remains unchanged."
  (let ((python (make-treesit-auto-recipe
                 :lang 'python :revision "main"
                 :url "https://example.test/python")))
    (should-not (cj/treesit-auto-pin-go-revision (list python)))
    (should (equal (treesit-auto-recipe-revision python) "main"))))

(ert-deftest test-prog-general-pin-go-treesit-revision-empty-is-no-op ()
  "Boundary: an empty recipe list does not signal an error."
  (should-not (cj/treesit-auto-pin-go-revision nil)))

(ert-deftest test-prog-general-pin-go-treesit-revision-malformed-recipe-errors ()
  "Error: a malformed recipe signals instead of silently skipping the pin."
  (should-error (cj/treesit-auto-pin-go-revision '(not-a-recipe))
                :type 'wrong-type-argument))

(provide 'test-prog-general--pin-go-treesit-revision)
;;; test-prog-general--pin-go-treesit-revision.el ends here