blob: eeb40ed313e19e486b52589673b2db7de523d00f (
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
|
;;; test-ai-term--displayed-agent-window.el --- Tests for the displayed-window helper -*- lexical-binding: t; -*-
;;; Commentary:
;; The helper returns a window in the selected frame whose buffer
;; satisfies `cj/--ai-term-buffer-p', or nil when no such window
;; exists. Used by F9 dispatch and M-F9 in-place replacement.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
(require 'ai-term)
(require 'testutil-ghostel-buffers)
(ert-deftest test-ai-term--displayed-agent-window-no-buffers-returns-nil ()
"Boundary: no agent buffers anywhere -> nil."
(cj/test--kill-agent-buffers)
(save-window-excursion
(delete-other-windows)
(should-not (cj/--ai-term-displayed-agent-window))))
(ert-deftest test-ai-term--displayed-agent-window-not-displayed-returns-nil ()
"Boundary: agent buffer exists but not in any window -> nil."
(cj/test--kill-agent-buffers)
(let ((b1 (get-buffer-create "agent [hidden]")))
(unwind-protect
(save-window-excursion
(delete-other-windows)
(should-not (cj/--ai-term-displayed-agent-window)))
(kill-buffer b1))))
(ert-deftest test-ai-term--displayed-agent-window-returns-window-when-displayed ()
"Normal: agent buffer in a window -> returns that window."
(cj/test--kill-agent-buffers)
(let ((b1 (get-buffer-create "agent [shown]")))
(unwind-protect
(save-window-excursion
(delete-other-windows)
(let ((win (split-window-right)))
(set-window-buffer win b1)
(let ((result (cj/--ai-term-displayed-agent-window)))
(should (windowp result))
(should (eq (window-buffer result) b1)))))
(kill-buffer b1))))
(ert-deftest test-ai-term--displayed-agent-window-ignores-non-agent-windows ()
"Boundary: only a non-agent buffer is displayed -> nil."
(cj/test--kill-agent-buffers)
(let ((other (get-buffer-create "regular-displayed-buffer")))
(unwind-protect
(save-window-excursion
(delete-other-windows)
(set-window-buffer (selected-window) other)
(should-not (cj/--ai-term-displayed-agent-window)))
(kill-buffer other))))
(provide 'test-ai-term--displayed-agent-window)
;;; test-ai-term--displayed-agent-window.el ends here
|