From 6cf0aac96ae0abb455ee8525e0ede9a63f5974f3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 4 Nov 2025 07:56:31 -0600 Subject: Add comprehensive ERT test suite and fix critical bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Session 1: Testing infrastructure and initial test coverage Bug fixes in wttrin.el: - Fix wttrin-additional-url-params to handle nil unit system - Remove incorrect callback parameter to url-retrieve-synchronously - Add nil buffer check for network failures - Strip HTTP headers before decoding response - Kill buffer after fetch to prevent memory leaks - Fix double concatenation of URL params in cache function - Add proper URL encoding via new wttrin--build-url function Refactoring: - Extract wttrin--build-url as pure, testable function - Separate URL building logic from network I/O Test infrastructure (33 tests, 100% passing): - tests/testutil-wttrin.el: Shared test utilities - tests/test-wttrin-additional-url-params.el: 7 tests - tests/test-wttrin--make-cache-key.el: 9 tests - tests/test-wttrin--build-url.el: 10 tests - tests/test-wttrin--cleanup-cache-if-needed.el: 7 tests Documentation: - docs/testing-plan.org: Comprehensive testing roadmap - docs/bugs.org: Bug analysis from code review - docs/NOTES.org: Session tracking and guidelines - docs/session-1-summary.org: Detailed session summary Next session: Cache workflow tests, parsing logic extraction, integration tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tests/test-wttrin--make-cache-key.el | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test-wttrin--make-cache-key.el (limited to 'tests/test-wttrin--make-cache-key.el') diff --git a/tests/test-wttrin--make-cache-key.el b/tests/test-wttrin--make-cache-key.el new file mode 100644 index 0000000..442c548 --- /dev/null +++ b/tests/test-wttrin--make-cache-key.el @@ -0,0 +1,69 @@ +;;; test-wttrin--make-cache-key.el --- Tests for wttrin--make-cache-key -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin--make-cache-key function. +;; Tests cache key generation from location and unit system. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Normal Cases + +(ert-deftest test-wttrin--make-cache-key-normal-location-with-metric-returns-key () + "Test that location with metric unit system creates correct cache key." + (testutil-wttrin-with-unit-system "m" + (should (equal "Paris|m" (wttrin--make-cache-key "Paris"))))) + +(ert-deftest test-wttrin--make-cache-key-normal-location-with-uscs-returns-key () + "Test that location with USCS unit system creates correct cache key." + (testutil-wttrin-with-unit-system "u" + (should (equal "New York|u" (wttrin--make-cache-key "New York"))))) + +(ert-deftest test-wttrin--make-cache-key-normal-location-no-unit-returns-default () + "Test that location with no unit system uses default in cache key." + (testutil-wttrin-with-unit-system nil + (should (equal "London|default" (wttrin--make-cache-key "London"))))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--make-cache-key-boundary-empty-location-returns-key () + "Test that empty location string creates cache key." + (testutil-wttrin-with-unit-system "m" + (should (equal "|m" (wttrin--make-cache-key ""))))) + +(ert-deftest test-wttrin--make-cache-key-boundary-location-with-spaces-returns-key () + "Test that location with spaces creates correct cache key." + (testutil-wttrin-with-unit-system "m" + (should (equal "New York, NY|m" (wttrin--make-cache-key "New York, NY"))))) + +(ert-deftest test-wttrin--make-cache-key-boundary-location-with-commas-returns-key () + "Test that location with commas creates correct cache key." + (testutil-wttrin-with-unit-system nil + (should (equal "Berlin, DE|default" (wttrin--make-cache-key "Berlin, DE"))))) + +(ert-deftest test-wttrin--make-cache-key-boundary-unicode-location-returns-key () + "Test that Unicode location creates correct cache key." + (testutil-wttrin-with-unit-system "m" + (should (equal "東京|m" (wttrin--make-cache-key "東京"))))) + +(ert-deftest test-wttrin--make-cache-key-boundary-location-with-special-chars-returns-key () + "Test that location with special characters creates cache key." + (testutil-wttrin-with-unit-system "m" + (should (equal "~Eiffel+Tower|m" (wttrin--make-cache-key "~Eiffel+Tower"))))) + +;;; Error Cases + +(ert-deftest test-wttrin--make-cache-key-error-nil-location-returns-key () + "Test that nil location creates cache key with empty string." + ;; Note: concat converts nil to empty string, this documents current behavior + (testutil-wttrin-with-unit-system "m" + (should (equal "|m" (wttrin--make-cache-key nil))))) + +(provide 'test-wttrin--make-cache-key) +;;; test-wttrin--make-cache-key.el ends here -- cgit v1.2.3