From 47130cec2000f741bdcf61827c03226fd0301bc0 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 8 Nov 2025 11:26:22 -0600 Subject: test: render: add comprehensive ERT tests for display helper functions Add 34 new tests covering the three helper functions extracted from wttrin--display-weather: - test-wttrin--validate-weather-data.el (12 tests) - test-wttrin--process-weather-content.el (12 tests) - test-wttrin--add-buffer-instructions.el (10 tests) Tests follow Normal/Boundary/Error pattern and all pass. Co-Authored-By: Claude --- tests/test-wttrin--validate-weather-data.el | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/test-wttrin--validate-weather-data.el (limited to 'tests/test-wttrin--validate-weather-data.el') diff --git a/tests/test-wttrin--validate-weather-data.el b/tests/test-wttrin--validate-weather-data.el new file mode 100644 index 0000000..651fb5c --- /dev/null +++ b/tests/test-wttrin--validate-weather-data.el @@ -0,0 +1,73 @@ +;;; test-wttrin--validate-weather-data.el --- Tests for wttrin--validate-weather-data -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Craig Jennings + +;;; Commentary: +;; Unit tests for wttrin--validate-weather-data function. +;; Tests validation of weather data strings for errors and nil values. + +;;; Code: + +(require 'ert) +(require 'wttrin) + +;;; Normal Cases + +(ert-deftest test-wttrin--validate-weather-data-normal-valid-weather-string () + "Test that valid weather data string is accepted." + (let ((valid-weather "Weather: 20°C\nCondition: Sunny\nWind: 10 km/h")) + (should (wttrin--validate-weather-data valid-weather)))) + +(ert-deftest test-wttrin--validate-weather-data-normal-multiline-weather () + "Test that multiline weather data is accepted." + (let ((weather "┌─────────────┐\n│ Weather │\n│ 20°C │\n└─────────────┘")) + (should (wttrin--validate-weather-data weather)))) + +(ert-deftest test-wttrin--validate-weather-data-normal-weather-with-unicode () + "Test that weather data with Unicode characters is accepted." + (let ((weather "Temperature: 20°C ☀️\nWind: 15 km/h 💨")) + (should (wttrin--validate-weather-data weather)))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--validate-weather-data-boundary-empty-string () + "Test that empty string is considered valid (though unusual)." + (should (wttrin--validate-weather-data ""))) + +(ert-deftest test-wttrin--validate-weather-data-boundary-whitespace-only () + "Test that whitespace-only string is considered valid." + (should (wttrin--validate-weather-data " \n \t "))) + +(ert-deftest test-wttrin--validate-weather-data-boundary-single-character () + "Test that single character string is valid." + (should (wttrin--validate-weather-data "x"))) + +(ert-deftest test-wttrin--validate-weather-data-boundary-error-lowercase () + "Test that lowercase 'error' is rejected (case-insensitive matching)." + ;; string-match uses case-fold-search which defaults to t in Emacs + (should-not (wttrin--validate-weather-data "error: connection failed"))) + +(ert-deftest test-wttrin--validate-weather-data-boundary-error-in-middle () + "Test that 'ERROR' anywhere in string causes rejection." + (should-not (wttrin--validate-weather-data "Weather: ERROR occurred while fetching"))) + +;;; Error Cases + +(ert-deftest test-wttrin--validate-weather-data-error-nil-string () + "Test that nil string is rejected." + (should-not (wttrin--validate-weather-data nil))) + +(ert-deftest test-wttrin--validate-weather-data-error-uppercase-error () + "Test that string containing 'ERROR' is rejected." + (should-not (wttrin--validate-weather-data "ERROR: Unable to fetch weather"))) + +(ert-deftest test-wttrin--validate-weather-data-error-error-at-start () + "Test that 'ERROR' at start of string causes rejection." + (should-not (wttrin--validate-weather-data "ERROR 404"))) + +(ert-deftest test-wttrin--validate-weather-data-error-error-at-end () + "Test that 'ERROR' at end of string causes rejection." + (should-not (wttrin--validate-weather-data "Network ERROR"))) + +(provide 'test-wttrin--validate-weather-data) +;;; test-wttrin--validate-weather-data.el ends here -- cgit v1.2.3