aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-cj-window-geometry-lib.el29
-rw-r--r--tests/test-cj-window-toggle-lib.el71
2 files changed, 100 insertions, 0 deletions
diff --git a/tests/test-cj-window-geometry-lib.el b/tests/test-cj-window-geometry-lib.el
index 2b417425..05ed9595 100644
--- a/tests/test-cj-window-geometry-lib.el
+++ b/tests/test-cj-window-geometry-lib.el
@@ -168,5 +168,34 @@ window forms the full-height right half -> nil."
(should (null (cj/window-at-edge 'sideways)))
(should (null (cj/window-at-edge nil)))))
+;; ----------------------------- window-size-fraction -----------------------------
+
+(ert-deftest test-cj-window-geometry-size-fraction-normal ()
+ "Normal: a window half the frame returns 0.5."
+ (should (= (cj/window-size-fraction 20 40) 0.5)))
+
+(ert-deftest test-cj-window-geometry-size-fraction-clamps-high ()
+ "Boundary: a near-full window is clamped to the 0.95 ceiling."
+ (should (= (cj/window-size-fraction 40 40) 0.95)))
+
+(ert-deftest test-cj-window-geometry-size-fraction-clamps-low ()
+ "Boundary: a vanishingly small window is clamped to the 0.05 floor."
+ (should (= (cj/window-size-fraction 0 40) 0.05)))
+
+(ert-deftest test-cj-window-geometry-size-fraction-custom-bounds ()
+ "Boundary: explicit MIN-FRAC/MAX-FRAC override the defaults."
+ (should (= (cj/window-size-fraction 1 40 0.1 0.9) 0.1))
+ (should (= (cj/window-size-fraction 39 40 0.1 0.9) 0.9)))
+
+(ert-deftest test-cj-window-geometry-size-fraction-zero-frame-nil ()
+ "Error: a non-positive frame size returns nil (no divide-by-zero)."
+ (should (null (cj/window-size-fraction 20 0)))
+ (should (null (cj/window-size-fraction 20 -5))))
+
+(ert-deftest test-cj-window-geometry-size-fraction-non-number-nil ()
+ "Error: non-numeric arguments return nil."
+ (should (null (cj/window-size-fraction nil 40)))
+ (should (null (cj/window-size-fraction 20 nil))))
+
(provide 'test-cj-window-geometry-lib)
;;; test-cj-window-geometry-lib.el ends here
diff --git a/tests/test-cj-window-toggle-lib.el b/tests/test-cj-window-toggle-lib.el
index 2c4ea831..ca4b7fef 100644
--- a/tests/test-cj-window-toggle-lib.el
+++ b/tests/test-cj-window-toggle-lib.el
@@ -184,5 +184,76 @@
(should (eq (cdr (assq 'direction received-alist)) 'bottom))
(should (= (cdr (assq 'window-height received-alist)) 0.4))))
+;; --------------------------- side-window helpers ---------------------------
+
+(defvar test-cj-side-window--size nil)
+
+(ert-deftest test-cj-side-window-capture-records-bottom-height ()
+ "Normal: a bottom side window writes a height fraction into the size var."
+ (save-window-excursion
+ (delete-other-windows)
+ (let* ((buf (get-buffer-create "*cj-side-test*"))
+ (win (display-buffer-in-side-window
+ buf '((side . bottom) (window-height . 0.5))))
+ (test-cj-side-window--size nil))
+ (unwind-protect
+ (progn
+ (cj/side-window-capture-size win 'bottom 'test-cj-side-window--size)
+ (should (floatp test-cj-side-window--size))
+ (should (<= 0.05 test-cj-side-window--size 0.95)))
+ (when (window-live-p win) (delete-window win))
+ (kill-buffer buf)))))
+
+(ert-deftest test-cj-side-window-capture-noop-on-nil-window ()
+ "Error: nil window leaves the size var unchanged."
+ (let ((test-cj-side-window--size 0.42))
+ (cj/side-window-capture-size nil 'bottom 'test-cj-side-window--size)
+ (should (= test-cj-side-window--size 0.42))))
+
+(ert-deftest test-cj-side-window-capture-noop-on-deleted-window ()
+ "Error: a deleted window leaves the size var unchanged."
+ (let ((test-cj-side-window--size 0.42)
+ (dead (save-window-excursion
+ (delete-other-windows)
+ (let* ((buf (get-buffer-create "*cj-side-dead*"))
+ (w (display-buffer-in-side-window
+ buf '((side . bottom) (window-height . 0.5)))))
+ (delete-window w)
+ (kill-buffer buf)
+ w))))
+ (cj/side-window-capture-size dead 'bottom 'test-cj-side-window--size)
+ (should (= test-cj-side-window--size 0.42))))
+
+(ert-deftest test-cj-side-window-display-uses-default-when-state-nil ()
+ "Normal: nil state -> default size under window-height for a bottom side."
+ (let (received-alist
+ (test-cj-side-window--size nil))
+ (cl-letf (((symbol-function 'display-buffer-in-side-window)
+ (lambda (_b a) (setq received-alist a) 'fake-window)))
+ (cj/side-window-display 'fake-buf 'bottom 'test-cj-side-window--size 0.3))
+ (should (eq (cdr (assq 'side received-alist)) 'bottom))
+ (should (= (cdr (assq 'window-height received-alist)) 0.3))
+ (should-not (assq 'window-width received-alist))))
+
+(ert-deftest test-cj-side-window-display-uses-stored-size ()
+ "Normal: a stored fraction overrides the default."
+ (let (received-alist
+ (test-cj-side-window--size 0.55))
+ (cl-letf (((symbol-function 'display-buffer-in-side-window)
+ (lambda (_b a) (setq received-alist a) 'fake-window)))
+ (cj/side-window-display 'fake-buf 'bottom 'test-cj-side-window--size 0.3))
+ (should (= (cdr (assq 'window-height received-alist)) 0.55))))
+
+(ert-deftest test-cj-side-window-display-left-uses-window-width ()
+ "Boundary: a left side puts the size under window-width, not window-height."
+ (let (received-alist
+ (test-cj-side-window--size nil))
+ (cl-letf (((symbol-function 'display-buffer-in-side-window)
+ (lambda (_b a) (setq received-alist a) 'fake-window)))
+ (cj/side-window-display 'fake-buf 'left 'test-cj-side-window--size 0.25))
+ (should (eq (cdr (assq 'side received-alist)) 'left))
+ (should (= (cdr (assq 'window-width received-alist)) 0.25))
+ (should-not (assq 'window-height received-alist))))
+
(provide 'test-cj-window-toggle-lib)
;;; test-cj-window-toggle-lib.el ends here