summaryrefslogtreecommitdiff
path: root/tests/testutil-wttrin.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testutil-wttrin.el')
-rw-r--r--tests/testutil-wttrin.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/testutil-wttrin.el b/tests/testutil-wttrin.el
index 0e109ad..685cc09 100644
--- a/tests/testutil-wttrin.el
+++ b/tests/testutil-wttrin.el
@@ -27,6 +27,25 @@
"ERROR: Unknown location; please try ~curl wttr.in/:help"
"Sample error response from wttr.in service.")
+(defconst testutil-wttrin-sample-ansi-response
+ "Weather report: Paris
+
+\x1b[38;5;226m \\ /\x1b[0m Partly cloudy
+\x1b[38;5;226m _ /\"\"\x1b[38;5;250m.-.\x1b[0m \x1b[38;5;118m+13\x1b[0m(\x1b[38;5;082m12\x1b[0m) °C
+\x1b[38;5;226m \\_\x1b[38;5;250m( ). \x1b[0m ↑ \x1b[38;5;190m12\x1b[0m km/h
+"
+ "Sample weather data with ANSI color codes for testing rendering.")
+
+(defconst testutil-wttrin-sample-full-weather
+ "Weather for Berkeley, CA
+
+ \\ / Clear
+ .-. 62 °F
+ ― ( ) ― ↑ 5 mph
+ `-' 10 mi
+ / \\ 0.0 in"
+ "Sample full weather display data for integration tests.")
+
;;; Cache Testing Helpers
(defun testutil-wttrin-clear-cache ()
@@ -65,6 +84,32 @@
`(let ((wttrin-cache-max-entries ,max-entries))
,@body))
+;;; Buffer Management
+
+(defmacro testutil-wttrin-with-clean-weather-buffer (&rest body)
+ "Execute BODY with clean *wttr.in* buffer setup/teardown."
+ (declare (indent 0))
+ `(progn
+ (when (get-buffer "*wttr.in*")
+ (kill-buffer "*wttr.in*"))
+ (unwind-protect
+ (progn ,@body)
+ (when (get-buffer "*wttr.in*")
+ (kill-buffer "*wttr.in*")))))
+
+;;; HTTP Mock Helpers
+
+(defmacro testutil-wttrin-mock-http-response (response-body &rest body)
+ "Mock url-retrieve to return HTTP 200 with RESPONSE-BODY, execute BODY."
+ (declare (indent 1))
+ `(cl-letf (((symbol-function 'url-retrieve)
+ (lambda (url callback)
+ (with-temp-buffer
+ (insert "HTTP/1.1 200 OK\n\n")
+ (insert ,response-body)
+ (funcall callback nil)))))
+ ,@body))
+
;;; Test Setup and Teardown
(defun testutil-wttrin-setup ()