aboutsummaryrefslogtreecommitdiff
path: root/archive/gptel/tests/test-ai-config-model-to-symbol.el
blob: de6f18ff841f3afc24943b2a4e44799485ed50a1 (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
52
53
54
55
56
57
58
59
60
61
;;; test-ai-config-model-to-symbol.el --- Tests for cj/gptel--model-to-symbol -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for cj/gptel--model-to-symbol from ai-config.el.
;;
;; Pure function that coerces a model identifier (string, symbol, or other
;; type) to a symbol.  `gptel-model' MUST be a symbol -- gptel's modeline
;; code calls `symbolp' on it and signals wrong-type-argument on a string,
;; which manifests as a redisplay hang.  The function's invariant is that
;; the result is always a symbol, so a value coerced through it is safe to
;; assign to `gptel-model'.

;;; Code:

(require 'ert)

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

;;; Normal Cases

(ert-deftest test-ai-config-model-to-symbol-normal-string-interns ()
  "Normal: a string model name is interned to the matching symbol."
  (should (eq (cj/gptel--model-to-symbol "claude-opus-4-8") 'claude-opus-4-8)))

(ert-deftest test-ai-config-model-to-symbol-normal-symbol-returns-symbol ()
  "Normal: a symbol model name is returned unchanged."
  (should (eq (cj/gptel--model-to-symbol 'gpt-4o) 'gpt-4o)))

(ert-deftest test-ai-config-model-to-symbol-normal-result-always-symbol ()
  "Normal: the invariant -- the result is always a symbol (the crash guard)."
  (should (symbolp (cj/gptel--model-to-symbol "gpt-5.5")))
  (should (symbolp (cj/gptel--model-to-symbol 'gpt-5.5))))

;;; Boundary Cases

(ert-deftest test-ai-config-model-to-symbol-boundary-empty-string-is-symbol ()
  "Boundary: empty string interns to a symbol (still satisfies the invariant)."
  (should (symbolp (cj/gptel--model-to-symbol ""))))

(ert-deftest test-ai-config-model-to-symbol-boundary-nil-returns-nil ()
  "Boundary: nil is already a symbol, returned unchanged."
  (should (eq (cj/gptel--model-to-symbol nil) nil))
  (should (symbolp (cj/gptel--model-to-symbol nil))))

(ert-deftest test-ai-config-model-to-symbol-boundary-string-with-spaces-interns ()
  "Boundary: a string with spaces interns to a single symbol with that name."
  (should (eq (cj/gptel--model-to-symbol "model with spaces")
              (intern "model with spaces"))))

;;; Error/Odd Cases

(ert-deftest test-ai-config-model-to-symbol-number-formats-then-interns ()
  "Error: a non-string, non-symbol value is formatted then interned to a symbol."
  (should (eq (cj/gptel--model-to-symbol 42) (intern "42")))
  (should (symbolp (cj/gptel--model-to-symbol 42))))

(provide 'test-ai-config-model-to-symbol)
;;; test-ai-config-model-to-symbol.el ends here