From 5463f104165185501be9cd6f7458d1b0cad856de Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 16:37:11 -0500 Subject: fix: weather buffer shows location in lowercase wttr.in returns "Weather report: new orleans, la" regardless of query casing. Replace the lowercase location on the header line with the user's original string after rendering. --- tests/test-wttrin--display-weather.el | 43 +++++++++++++++++++++++++++++++++++ wttrin.el | 4 ++++ 2 files changed, 47 insertions(+) diff --git a/tests/test-wttrin--display-weather.el b/tests/test-wttrin--display-weather.el index 6417995..b30c5b5 100644 --- a/tests/test-wttrin--display-weather.el +++ b/tests/test-wttrin--display-weather.el @@ -200,5 +200,48 @@ Empty string does not match ERROR pattern, so it's processed as data." (buffer-name (current-buffer)))))) (test-wttrin--display-weather-teardown))) +;;; Location Casing + +(ert-deftest test-wttrin--display-weather-normal-location-uses-user-casing () + "The 'Weather report:' header should show the user's original casing, +not the lowercase version that wttr.in returns." + (test-wttrin--display-weather-setup) + (unwind-protect + (testutil-wttrin-with-clean-weather-buffer + (wttrin--display-weather "New Orleans, LA" + "Weather report: new orleans, la\n\nSunny 72°F") + (with-current-buffer "*wttr.in*" + (let ((case-fold-search nil)) + (goto-char (point-min)) + (should (search-forward "New Orleans, LA" nil t)) + (goto-char (point-min)) + (should-not (search-forward "new orleans, la" nil t))))) + (test-wttrin--display-weather-teardown))) + +(ert-deftest test-wttrin--display-weather-boundary-location-already-correct () + "When the API returns correct casing, nothing should break." + (test-wttrin--display-weather-setup) + (unwind-protect + (testutil-wttrin-with-clean-weather-buffer + (wttrin--display-weather "Paris" + "Weather report: Paris\n\nSunny 22°C") + (with-current-buffer "*wttr.in*" + (goto-char (point-min)) + (should (search-forward "Paris" nil t)))) + (test-wttrin--display-weather-teardown))) + +(ert-deftest test-wttrin--display-weather-normal-weather-data-preserved () + "Fixing the location casing should not alter the weather data itself." + (test-wttrin--display-weather-setup) + (unwind-protect + (testutil-wttrin-with-clean-weather-buffer + (wttrin--display-weather "Tokyo" + "Weather report: tokyo\n\nCloudy 18°C\nWind: 5 km/h") + (with-current-buffer "*wttr.in*" + (let ((contents (buffer-string))) + (should (string-match-p "Cloudy 18°C" contents)) + (should (string-match-p "Wind: 5 km/h" contents))))) + (test-wttrin--display-weather-teardown))) + (provide 'test-wttrin--display-weather) ;;; test-wttrin--display-weather.el ends here diff --git a/wttrin.el b/wttrin.el index b628b1c..2dc231d 100644 --- a/wttrin.el +++ b/wttrin.el @@ -451,6 +451,10 @@ the generic error message." (require 'xterm-color) (setq-local xterm-color--state :char) (insert (wttrin--process-weather-content raw-string)) + ;; wttr.in returns location in lowercase — replace with user's casing + (goto-char (point-min)) + (when (re-search-forward "^Weather report: .*$" nil t) + (replace-match (concat "Weather report: " location-name))) (let ((staleness (wttrin--format-staleness-header location-name))) (when staleness (insert "\n" staleness))) -- cgit v1.2.3