aboutsummaryrefslogtreecommitdiff
path: root/tests/test-debug-wttrin-show-raw.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 12:34:34 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 12:34:34 -0500
commitf33d7231fa7f9f11250a592e28601df6b8f564c7 (patch)
tree45d44a7076e1c731033bc914e7e7a8af4c5b4108 /tests/test-debug-wttrin-show-raw.el
parentea5636c51361b86d132d647ee3548d208394878e (diff)
downloademacs-wttrin-f33d7231fa7f9f11250a592e28601df6b8f564c7.tar.gz
emacs-wttrin-f33d7231fa7f9f11250a592e28601df6b8f564c7.zip
fix: debug-wttrin-show-raw broken by async API change
debug-wttrin-show-raw called wttrin--get-cached-or-fetch with 1 arg, but the function now requires 2 (location + callback) since the async refactor. Rewrote to use the callback pattern. Also handles nil response gracefully.
Diffstat (limited to 'tests/test-debug-wttrin-show-raw.el')
-rw-r--r--tests/test-debug-wttrin-show-raw.el104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/test-debug-wttrin-show-raw.el b/tests/test-debug-wttrin-show-raw.el
new file mode 100644
index 0000000..ae2f750
--- /dev/null
+++ b/tests/test-debug-wttrin-show-raw.el
@@ -0,0 +1,104 @@
+;;; test-debug-wttrin-show-raw.el --- Tests for debug-wttrin-show-raw -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for debug-wttrin-show-raw function.
+;; Tests that the debug display shows raw weather data with line numbers.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+;; Load wttrin-debug for the function under test
+(require 'wttrin-debug
+ (expand-file-name "wttrin-debug.el"
+ (file-name-directory (locate-library "wttrin"))))
+
+;;; Setup and Teardown
+
+(defun test-debug-wttrin-show-raw-setup ()
+ "Setup for debug-wttrin-show-raw tests."
+ (testutil-wttrin-setup)
+ (when (get-buffer "*wttrin-debug*")
+ (kill-buffer "*wttrin-debug*")))
+
+(defun test-debug-wttrin-show-raw-teardown ()
+ "Teardown for debug-wttrin-show-raw tests."
+ (testutil-wttrin-teardown)
+ (when (get-buffer "*wttrin-debug*")
+ (kill-buffer "*wttrin-debug*")))
+
+;;; Normal Cases
+
+(ert-deftest test-debug-wttrin-show-raw-normal-creates-debug-buffer ()
+ "Calling show-raw should create the *wttrin-debug* buffer."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (progn
+ (testutil-wttrin-mock-http-response "Line one\nLine two\nLine three"
+ (debug-wttrin-show-raw "Paris"))
+ (should (get-buffer "*wttrin-debug*")))
+ (test-debug-wttrin-show-raw-teardown)))
+
+(ert-deftest test-debug-wttrin-show-raw-normal-adds-line-numbers ()
+ "Each line of raw data should be prefixed with its line number."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (progn
+ (testutil-wttrin-mock-http-response "Alpha\nBravo\nCharlie"
+ (debug-wttrin-show-raw "Paris"))
+ (with-current-buffer "*wttrin-debug*"
+ (let ((contents (buffer-string)))
+ (should (string-match-p "^ *1: Alpha" contents))
+ (should (string-match-p "^ *2: Bravo" contents))
+ (should (string-match-p "^ *3: Charlie" contents)))))
+ (test-debug-wttrin-show-raw-teardown)))
+
+(ert-deftest test-debug-wttrin-show-raw-normal-fetches-correct-location ()
+ "The function should fetch weather for the specified location."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (let ((fetched-location nil))
+ (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch)
+ (lambda (location callback)
+ (setq fetched-location location)
+ (funcall callback "data"))))
+ (debug-wttrin-show-raw "Berlin, DE")
+ (should (equal fetched-location "Berlin, DE"))))
+ (test-debug-wttrin-show-raw-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-debug-wttrin-show-raw-boundary-single-line ()
+ "Single-line response should get line number 1."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (progn
+ (testutil-wttrin-mock-http-response "Just one line"
+ (debug-wttrin-show-raw "Paris"))
+ (with-current-buffer "*wttrin-debug*"
+ (let ((contents (buffer-string)))
+ (should (string-match-p "^ *1: Just one line" contents)))))
+ (test-debug-wttrin-show-raw-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-debug-wttrin-show-raw-error-nil-response-should-not-crash ()
+ "When the fetch returns nil, the function should handle it gracefully."
+ (test-debug-wttrin-show-raw-setup)
+ (unwind-protect
+ (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch)
+ (lambda (_location callback)
+ (funcall callback nil))))
+ ;; Should not crash
+ (debug-wttrin-show-raw "BadLocation")
+ ;; Buffer should exist even on error
+ (should (get-buffer "*wttrin-debug*")))
+ (test-debug-wttrin-show-raw-teardown)))
+
+(provide 'test-debug-wttrin-show-raw)
+;;; test-debug-wttrin-show-raw.el ends here