aboutsummaryrefslogtreecommitdiff
path: root/tests/test-ai-config--apply-model-selection.el
blob: 4ccd6d7a0da73c52a38d470936bd9fdafef7e51a (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
;;; test-ai-config--apply-model-selection.el --- Tests for cj/--gptel-apply-model-selection -*- lexical-binding: t; -*-

;;; Commentary:
;; cj/--gptel-apply-model-selection is the apply step extracted from the
;; interactive cj/gptel-change-model: it sets gptel-backend/gptel-model globally
;; or buffer-locally and returns the confirmation message.  The extraction also
;; dropped a dead `(if (stringp model) ...)' branch (model is always a symbol by
;; that point).

;;; Code:

(require 'ert)

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

(defvar gptel-backend)
(defvar gptel-model)

(ert-deftest test-ai-config-apply-model-global-sets-globals ()
  "Normal: global scope assigns the global vars and reports (global)."
  (let ((gptel-backend nil) (gptel-model nil))
    (let ((msg (cj/--gptel-apply-model-selection "global" 'mybackend 'mymodel "MyAI")))
      (should (eq gptel-backend 'mybackend))
      (should (eq gptel-model 'mymodel))
      (should (string-match-p "MyAI" msg))
      (should (string-match-p "mymodel" msg))
      (should (string-match-p "global" msg)))))

(ert-deftest test-ai-config-apply-model-buffer-sets-buffer-locals ()
  "Normal: buffer scope makes the vars buffer-local and reports (buffer-local)."
  (let ((gptel-backend 'orig) (gptel-model 'origm))
    (with-temp-buffer
      (let ((msg (cj/--gptel-apply-model-selection "buffer" 'be 'mo "Name")))
        (should (local-variable-p 'gptel-backend))
        (should (local-variable-p 'gptel-model))
        (should (eq gptel-backend 'be))
        (should (eq gptel-model 'mo))
        (should (string-match-p "buffer-local" msg))))
    ;; outside the temp buffer the globals are untouched
    (should (eq gptel-backend 'orig))
    (should (eq gptel-model 'origm))))

(provide 'test-ai-config--apply-model-selection)
;;; test-ai-config--apply-model-selection.el ends here