aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-mode-initialization-order.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-wttrin-mode-initialization-order.el')
-rw-r--r--tests/test-wttrin-mode-initialization-order.el69
1 files changed, 37 insertions, 32 deletions
diff --git a/tests/test-wttrin-mode-initialization-order.el b/tests/test-wttrin-mode-initialization-order.el
index 20adf06..5ecd4bc 100644
--- a/tests/test-wttrin-mode-initialization-order.el
+++ b/tests/test-wttrin-mode-initialization-order.el
@@ -18,6 +18,8 @@
(require 'wttrin)
(require 'testutil-wttrin)
+;;; Setup and Teardown
+
(defun test-wttrin-mode-init-setup ()
"Setup for mode initialization tests."
(testutil-wttrin-setup)
@@ -30,7 +32,9 @@
(when (get-buffer "*wttr.in*")
(kill-buffer "*wttr.in*")))
-(ert-deftest test-wttrin-mode-initialization-order-mode-before-buffer-local-vars ()
+;;; Tests
+
+(ert-deftest test-wttrin-mode-initialization-order-normal-mode-before-buffer-local-vars-calls-mode-first ()
"Test that wttrin-mode is activated before setting buffer-local variables.
This test verifies the fix for the color rendering bug where xterm-color--state
@@ -43,45 +47,46 @@ The test strategy:
4. Verify wttrin-mode was called BEFORE any buffer-local vars were set"
(test-wttrin-mode-init-setup)
(unwind-protect
- (let ((mode-called-at nil)
- (first-setq-local-at nil)
- (call-counter 0))
-
- ;; Advise to track when wttrin-mode is called
- (cl-letf (((symbol-function 'wttrin-mode)
- (let ((orig-fn (symbol-function 'wttrin-mode)))
- (lambda ()
- (setq mode-called-at (cl-incf call-counter))
- (funcall orig-fn))))
-
- ;; Advise to track first buffer-local variable set
- ((symbol-function 'set)
- (let ((orig-fn (symbol-function 'set)))
- (lambda (symbol value)
- ;; Track xterm-color--state specifically
- (when (and (eq symbol 'xterm-color--state)
- (null first-setq-local-at))
- (setq first-setq-local-at (cl-incf call-counter)))
- (funcall orig-fn symbol value)))))
-
- (wttrin--display-weather "Paris" "Test weather data")
-
- ;; Verify mode was called
- (should mode-called-at)
- ;; Verify buffer-local var was set
- (should first-setq-local-at)
- ;; Critical: mode must be called BEFORE buffer-local var
- (should (< mode-called-at first-setq-local-at))))
+ (testutil-wttrin-with-clean-weather-buffer
+ (let ((mode-called-at nil)
+ (first-setq-local-at nil)
+ (call-counter 0))
+
+ ;; Advise to track when wttrin-mode is called
+ (cl-letf (((symbol-function 'wttrin-mode)
+ (let ((orig-fn (symbol-function 'wttrin-mode)))
+ (lambda ()
+ (setq mode-called-at (cl-incf call-counter))
+ (funcall orig-fn))))
+
+ ;; Advise to track first buffer-local variable set
+ ((symbol-function 'set)
+ (let ((orig-fn (symbol-function 'set)))
+ (lambda (symbol value)
+ ;; Track xterm-color--state specifically
+ (when (and (eq symbol 'xterm-color--state)
+ (null first-setq-local-at))
+ (setq first-setq-local-at (cl-incf call-counter)))
+ (funcall orig-fn symbol value)))))
+
+ (wttrin--display-weather "Paris" "Test weather data")
+
+ ;; Verify mode was called
+ (should mode-called-at)
+ ;; Verify buffer-local var was set
+ (should first-setq-local-at)
+ ;; Critical: mode must be called BEFORE buffer-local var
+ (should (< mode-called-at first-setq-local-at)))))
(test-wttrin-mode-init-teardown)))
-(ert-deftest test-wttrin-mode-initialization-order-xterm-color-state-survives ()
+(ert-deftest test-wttrin-mode-initialization-order-normal-xterm-color-state-survives-mode-init ()
"Test that xterm-color--state remains buffer-local after wttrin--display-weather.
This verifies that the state isn't wiped by kill-all-local-variables."
(test-wttrin-mode-init-setup)
(unwind-protect
- (progn
+ (testutil-wttrin-with-clean-weather-buffer
(wttrin--display-weather "London" "Test data")
(should (get-buffer "*wttr.in*"))