blob: 330714a92563bfc01fc71ee3beb2752a517f53a2 (
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
62
63
64
65
66
67
68
69
70
71
72
73
|
;;; test-ai-term--next-agent-buffer.el --- Tests for cj/--ai-term-next-agent-buffer -*- lexical-binding: t; -*-
;;; Commentary:
;; The pure decision helper behind `cj/ai-term-next' (s-F9). Given the
;; current agent buffer and the ordered list of live agent buffers, it
;; returns the next buffer in the queue, wrapping after the last. A nil
;; or non-member CURRENT returns the first; an empty list returns nil.
;; No buffer or window side effects -- list logic only.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'ai-term)
(ert-deftest test-ai-term--next-agent-buffer-advances-from-first ()
"Normal: current is the first element -> returns the second."
(let ((a (get-buffer-create "agent [a]"))
(b (get-buffer-create "agent [b]"))
(c (get-buffer-create "agent [c]")))
(unwind-protect
(should (eq b (cj/--ai-term-next-agent-buffer a (list a b c))))
(mapc #'kill-buffer (list a b c)))))
(ert-deftest test-ai-term--next-agent-buffer-advances-from-middle ()
"Normal: current in the middle -> returns the following element."
(let ((a (get-buffer-create "agent [a]"))
(b (get-buffer-create "agent [b]"))
(c (get-buffer-create "agent [c]")))
(unwind-protect
(should (eq c (cj/--ai-term-next-agent-buffer b (list a b c))))
(mapc #'kill-buffer (list a b c)))))
(ert-deftest test-ai-term--next-agent-buffer-wraps-after-last ()
"Boundary: current is the last element -> wraps to the first."
(let ((a (get-buffer-create "agent [a]"))
(b (get-buffer-create "agent [b]"))
(c (get-buffer-create "agent [c]")))
(unwind-protect
(should (eq a (cj/--ai-term-next-agent-buffer c (list a b c))))
(mapc #'kill-buffer (list a b c)))))
(ert-deftest test-ai-term--next-agent-buffer-single-element-returns-itself ()
"Boundary: a one-agent queue wraps current back to itself."
(let ((a (get-buffer-create "agent [a]")))
(unwind-protect
(should (eq a (cj/--ai-term-next-agent-buffer a (list a))))
(kill-buffer a))))
(ert-deftest test-ai-term--next-agent-buffer-nil-current-returns-first ()
"Boundary: nil current (no agent displayed) -> returns the first."
(let ((a (get-buffer-create "agent [a]"))
(b (get-buffer-create "agent [b]")))
(unwind-protect
(should (eq a (cj/--ai-term-next-agent-buffer nil (list a b))))
(mapc #'kill-buffer (list a b)))))
(ert-deftest test-ai-term--next-agent-buffer-non-member-current-returns-first ()
"Error: current not in the queue -> returns the first rather than nil."
(let ((a (get-buffer-create "agent [a]"))
(b (get-buffer-create "agent [b]"))
(stray (get-buffer-create "agent [stray]")))
(unwind-protect
(should (eq a (cj/--ai-term-next-agent-buffer stray (list a b))))
(mapc #'kill-buffer (list a b stray)))))
(ert-deftest test-ai-term--next-agent-buffer-empty-queue-returns-nil ()
"Boundary: an empty queue returns nil (nothing to switch to)."
(should (null (cj/--ai-term-next-agent-buffer nil '()))))
(provide 'test-ai-term--next-agent-buffer)
;;; test-ai-term--next-agent-buffer.el ends here
|