blob: 0943a48883b1228719cb23b7e332f5f21864e966 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
;;; test-term-toggle--display.el --- Tests for the F12 display-saved action -*- lexical-binding: t; -*-
;;; Commentary:
;; Covers the F12-side equivalents of the ai-term display tests:
;; geometry capture (window-direction, window-size with 'below
;; default), capture-state writing module-level vars, and the custom
;; display action mapping cardinal -> edge directions. Tests stub
;; `display-buffer-in-direction' to capture the alist that would
;; have reached it.
;;; Code:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'term-config)
(ert-deftest test-term-toggle--capture-state-records-direction-and-size ()
"Normal: capture-state writes direction and integer body size."
(save-window-excursion
(delete-other-windows)
(let ((below (split-window (selected-window) nil 'below))
(cj/--term-toggle-last-direction nil)
(cj/--term-toggle-last-size nil))
(cj/--term-toggle-capture-state below)
(should (eq cj/--term-toggle-last-direction 'below))
(should (integerp cj/--term-toggle-last-size))
(should (= cj/--term-toggle-last-size (window-body-height below))))))
(ert-deftest test-term-toggle--capture-state-noop-on-dead-window ()
"Boundary: nil window -> state remains unchanged."
(let ((cj/--term-toggle-last-direction 'sentinel)
(cj/--term-toggle-last-size 0.123))
(cj/--term-toggle-capture-state nil)
(should (eq cj/--term-toggle-last-direction 'sentinel))
(should (= cj/--term-toggle-last-size 0.123))))
(ert-deftest test-term-toggle--display-saved-defaults-when-state-nil ()
"Normal: nil state -> direction=bottom, size=cj/term-toggle-window-height."
(let (received-alist
(cj/--term-toggle-last-direction nil)
(cj/--term-toggle-last-size nil)
(cj/term-toggle-window-height 0.7))
(cl-letf (((symbol-function 'display-buffer-in-direction)
(lambda (_b a) (setq received-alist a) 'fake-window)))
(cj/--term-toggle-display-saved 'fake-buf '((inhibit-same-window . t))))
(should (eq (cdr (assq 'direction received-alist)) 'bottom))
(should (= (cdr (assq 'window-height received-alist)) 0.7))
(should (eq (cdr (assq 'inhibit-same-window received-alist)) t))))
(ert-deftest test-term-toggle--display-saved-maps-cardinal-to-edge ()
"Normal: saved 'below maps to bottom edge; integer size wraps in body-lines."
(let (received-alist
(cj/--term-toggle-last-direction 'below)
(cj/--term-toggle-last-size 12))
(cl-letf (((symbol-function 'display-buffer-in-direction)
(lambda (_b a) (setq received-alist a) 'fake-window)))
(cj/--term-toggle-display-saved 'fake-buf nil))
(should (eq (cdr (assq 'direction received-alist)) 'bottom))
(should (equal (cdr (assq 'window-height received-alist))
'(body-lines . 12)))
(should-not (assq 'window-width received-alist))))
(ert-deftest test-term-toggle--display-saved-strips-conflicting-alist-entries ()
"Boundary: caller-supplied direction/size are stripped, saved values win."
(let (received-alist
(cj/--term-toggle-last-direction 'right)
(cj/--term-toggle-last-size 30))
(cl-letf (((symbol-function 'display-buffer-in-direction)
(lambda (_b a) (setq received-alist a) 'fake-window)))
(cj/--term-toggle-display-saved
'fake-buf
'((direction . above)
(window-width . 0.2)
(window-height . 0.3)
(inhibit-same-window . t))))
(should (eq (cdr (assq 'direction received-alist)) 'rightmost))
(should (equal (cdr (assq 'window-width received-alist))
'(body-columns . 30)))
(let ((wh-cells (cl-remove-if-not
(lambda (cell) (eq (car-safe cell) 'window-height))
received-alist)))
(should (null wh-cells)))))
(provide 'test-term-toggle--display)
;;; test-term-toggle--display.el ends here
|