aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-debug-mode-line.el
blob: b9e135b93da9680a1f04cad4f043c86a38aaf5ec (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
;;; test-wttrin-debug-mode-line.el --- Tests for wttrin-debug-mode-line -*- lexical-binding: t; -*-

;; Copyright (C) 2025-2026 Craig Jennings

;;; Commentary:

;; Unit tests for wttrin-debug-mode-line.  This function is a UI-heavy
;; diagnostic dump, so testing focuses on the two top-level branches:
;; - When *wttr.in* is missing, no diagnostic buffer is produced.
;; - When *wttr.in* exists, the diagnostic buffer is created and contains
;;   the expected section labels.

;;; Code:

(require 'ert)
(require 'wttrin)
(require 'testutil-wttrin)

(require 'wttrin-debug
         (expand-file-name "wttrin-debug.el"
                           (file-name-directory (locate-library "wttrin"))))

;;; Setup and Teardown

(defun test-wttrin-debug-mode-line-setup ()
  "Setup for wttrin-debug-mode-line tests."
  (when (get-buffer "*wttr.in*")
    (kill-buffer "*wttr.in*"))
  (when (get-buffer "*wttrin-mode-debug*")
    (kill-buffer "*wttrin-mode-debug*")))

(defun test-wttrin-debug-mode-line-teardown ()
  "Teardown for wttrin-debug-mode-line tests."
  (when (get-buffer "*wttr.in*")
    (kill-buffer "*wttr.in*"))
  (when (get-buffer "*wttrin-mode-debug*")
    (kill-buffer "*wttrin-mode-debug*")))

;;; Normal Cases

(ert-deftest test-wttrin-debug-mode-line-normal-no-buffer-skips-diagnostic-buffer ()
  "When the *wttr.in* buffer is absent, no diagnostic buffer is created."
  (test-wttrin-debug-mode-line-setup)
  (unwind-protect
      (progn
        (wttrin-debug-mode-line)
        (should-not (get-buffer "*wttrin-mode-debug*")))
    (test-wttrin-debug-mode-line-teardown)))

(ert-deftest test-wttrin-debug-mode-line-normal-buffer-exists-creates-diagnostic-buffer ()
  "When the *wttr.in* buffer exists, the diagnostic buffer is created."
  (test-wttrin-debug-mode-line-setup)
  (unwind-protect
      (progn
        (with-current-buffer (get-buffer-create "*wttr.in*")
          (wttrin-mode))
        (wttrin-debug-mode-line)
        (should (get-buffer "*wttrin-mode-debug*")))
    (test-wttrin-debug-mode-line-teardown)))

(ert-deftest test-wttrin-debug-mode-line-normal-diagnostic-buffer-contains-section-labels ()
  "Diagnostic buffer contains the expected section labels."
  (test-wttrin-debug-mode-line-setup)
  (unwind-protect
      (progn
        (with-current-buffer (get-buffer-create "*wttr.in*")
          (wttrin-mode))
        (wttrin-debug-mode-line)
        (with-current-buffer "*wttrin-mode-debug*"
          (let ((contents (buffer-string)))
            (should (string-match-p "Wttrin Mode-Line Debug Info" contents))
            (should (string-match-p "Buffer:" contents))
            (should (string-match-p "Major mode:" contents))
            (should (string-match-p "mode-name variable:" contents))
            (should (string-match-p "mode-line-format first 5 elements:" contents)))))
    (test-wttrin-debug-mode-line-teardown)))

(provide 'test-wttrin-debug-mode-line)
;;; test-wttrin-debug-mode-line.el ends here