diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 12:26:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 12:26:16 -0500 |
| commit | ea5636c51361b86d132d647ee3548d208394878e (patch) | |
| tree | a60ab847c7324417ca7de46e73d370ba2af90d05 /tests/test-wttrin-fetch-raw-string.el | |
| parent | b74b98f177d92d50ddbede900ba41212e07c5f63 (diff) | |
| download | emacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.tar.gz emacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.zip | |
test: add 50 tests for untested functions; fix nil crash in save-debug-data
Add 11 new test files covering wttrin--save-debug-data,
wttrin--buffer-cache-refresh, wttrin--mode-line-stop,
wttrin--mode-line-start, wttrin-query, wttrin-requery-force,
wttrin-mode-line-click, wttrin-mode-line-force-refresh,
wttrin-fetch-raw-string, wttrin-clear-cache, and wttrin-requery.
Fix bug in wttrin--save-debug-data where nil raw-string caused
(insert nil) crash — reachable when debug mode is on and fetch fails.
Refactor wttrin-requery: extract wttrin--requery-location so the
core kill-buffer-and-query logic is testable without mocking
completing-read.
267 tests total (was 217), all passing.
Diffstat (limited to 'tests/test-wttrin-fetch-raw-string.el')
| -rw-r--r-- | tests/test-wttrin-fetch-raw-string.el | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/test-wttrin-fetch-raw-string.el b/tests/test-wttrin-fetch-raw-string.el new file mode 100644 index 0000000..963fd29 --- /dev/null +++ b/tests/test-wttrin-fetch-raw-string.el @@ -0,0 +1,65 @@ +;;; test-wttrin-fetch-raw-string.el --- Tests for wttrin-fetch-raw-string -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-fetch-raw-string function. +;; Tests the public API for fetching weather data by location query. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Setup and Teardown + +(defun test-wttrin-fetch-raw-string-setup () + "Setup for fetch-raw-string tests." + (testutil-wttrin-setup)) + +(defun test-wttrin-fetch-raw-string-teardown () + "Teardown for fetch-raw-string tests." + (testutil-wttrin-teardown)) + +;;; Normal Cases + +(ert-deftest test-wttrin-fetch-raw-string-normal-builds-correct-url () + "The fetch should use a properly constructed wttr.in URL for the query." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (let ((fetched-url nil)) + (cl-letf (((symbol-function 'wttrin--fetch-url) + (lambda (url _callback) (setq fetched-url url)))) + (wttrin-fetch-raw-string "Paris" #'ignore) + ;; URL should contain wttr.in and the encoded location + (should (string-match-p "wttr\\.in" fetched-url)) + (should (string-match-p "Paris" fetched-url)))) + (test-wttrin-fetch-raw-string-teardown))) + +(ert-deftest test-wttrin-fetch-raw-string-normal-passes-callback-through () + "The user's callback should receive the fetched data." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (let ((received-data nil)) + (cl-letf (((symbol-function 'wttrin--fetch-url) + (lambda (_url callback) + (funcall callback "weather response")))) + (wttrin-fetch-raw-string "Paris" + (lambda (data) (setq received-data data))) + (should (equal received-data "weather response")))) + (test-wttrin-fetch-raw-string-teardown))) + +;;; Error Cases + +(ert-deftest test-wttrin-fetch-raw-string-error-nil-query-signals-error () + "Passing nil as query should signal an error (invalid URL construction)." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (should-error (wttrin-fetch-raw-string nil #'ignore) + :type 'error) + (test-wttrin-fetch-raw-string-teardown))) + +(provide 'test-wttrin-fetch-raw-string) +;;; test-wttrin-fetch-raw-string.el ends here |
