blob: 53d2e78fb3bbdcfa9079a87dd98258c5c61cad6b (
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
|
;;; test-calibredb-epub-config.el --- Tests for ebook config helpers -*- lexical-binding: t; -*-
;;; Commentary:
;; Focuses on project-owned helpers in calibredb-epub-config rather than
;; CalibreDB/Nov internals.
;;; Code:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'calibredb-epub-config)
(ert-deftest test-calibredb-epub-nov-text-width-default-window ()
"Normal: text width uses the configured margins against the current window."
(let ((cj/nov-margin-percent 25)
(cj/nov-min-text-width 40))
(cl-letf (((symbol-function 'get-buffer-window)
(lambda (&rest _) 'window))
((symbol-function 'window-body-width)
(lambda (_) 120)))
(should (= 60 (cj/nov--text-width-for-window))))))
(ert-deftest test-calibredb-epub-nov-text-width-clamps-large-margin ()
"Boundary: excessive margins are clamped to keep a readable text column."
(let ((cj/nov-margin-percent 80)
(cj/nov-min-text-width 40))
(cl-letf (((symbol-function 'get-buffer-window)
(lambda (&rest _) 'window))
((symbol-function 'window-body-width)
(lambda (_) 120)))
(should (= 40 (cj/nov--text-width-for-window))))))
(ert-deftest test-calibredb-epub-nov-text-width-fallback-without-window ()
"Boundary: a buffer without a visible window still gets a usable width."
(let ((cj/nov-margin-percent 25)
(cj/nov-min-text-width 40))
(cl-letf (((symbol-function 'get-buffer-window)
(lambda (&rest _) nil)))
(should (= 40 (cj/nov--text-width-for-window))))))
(ert-deftest test-calibredb-epub-nov-text-width-clamps-negative-margin ()
"Boundary: a negative margin percent is clamped up to 0, so the text takes
the full window width."
(let ((cj/nov-margin-percent -10)
(cj/nov-min-text-width 40))
(cl-letf (((symbol-function 'get-buffer-window)
(lambda (&rest _) 'window))
((symbol-function 'window-body-width)
(lambda (_) 120)))
(should (= 120 (cj/nov--text-width-for-window))))))
(ert-deftest test-calibredb-epub-open-external-uses-zathura ()
"Normal: named Nov external-open command delegates to zathura."
(let (command)
(cl-letf (((symbol-function 'cj/open-file-with-command)
(lambda (cmd) (setq command cmd))))
(cj/nov-open-external)
(should (equal command "zathura")))))
(provide 'test-calibredb-epub-config)
;;; test-calibredb-epub-config.el ends here
|