diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-26 18:32:02 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-26 18:32:02 -0500 |
| commit | 38a6a0a745022ed7f0336f7deb121d75f589a916 (patch) | |
| tree | b85a9dc15045e5de9fc3f7fae00f8a571de9c6a2 /tests | |
| parent | eabd510c302b43b0b40ee7b92bf5830d345d058d (diff) | |
| download | emacs-wttrin-38a6a0a745022ed7f0336f7deb121d75f589a916.tar.gz emacs-wttrin-38a6a0a745022ed7f0336f7deb121d75f589a916.zip | |
refactor: extract wttrin--mode-line-extract-emoji helper
The regex that pulls the emoji character out of a wttr.in mode-line response was inlined inside `wttrin--mode-line-update-display`, mixed in with the render logic. Six tests of the parser couldn't be written without invoking the whole render path.
The new pure helper takes the weather string, runs the regex, and returns either the first non-whitespace character after the colon or "?" as a placeholder. The format-explanation comment that used to sit above the inline code is gone now that the same explanation lives in the helper's docstring. There's no risk of comment and code drifting apart.
Six tests cover Normal (typical response, different emoji), Boundary (no whitespace after colon, multiple whitespace chars), and Error (no colon, empty string).
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-wttrin--mode-line-helpers.el | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test-wttrin--mode-line-helpers.el b/tests/test-wttrin--mode-line-helpers.el index 6eae822..408711b 100644 --- a/tests/test-wttrin--mode-line-helpers.el +++ b/tests/test-wttrin--mode-line-helpers.el @@ -171,5 +171,45 @@ distinguish a missing key from a present key bound to nil." "Nil cache-entry returns nil with no signal." (should-not (wttrin--mode-line-stale-p nil))) +;;; -------------------------------------------------------------------------- +;;; wttrin--mode-line-extract-emoji +;;; -------------------------------------------------------------------------- + +;;; Normal Cases + +(ert-deftest test-wttrin--mode-line-extract-emoji-normal-typical-response () + "Typical response \"Location: emoji rest\" returns the emoji." + (should (equal (wttrin--mode-line-extract-emoji "Paris: ☀ +72°F Clear") + "☀"))) + +(ert-deftest test-wttrin--mode-line-extract-emoji-normal-different-emoji () + "Different emoji is returned correctly (no hardcoded match)." + (should (equal (wttrin--mode-line-extract-emoji "London: ⛅ +15°C Cloudy") + "⛅"))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--mode-line-extract-emoji-boundary-no-whitespace-after-colon () + "Colon with no whitespace before the emoji still extracts." + (should (equal (wttrin--mode-line-extract-emoji "X:Y rest") + "Y"))) + +(ert-deftest test-wttrin--mode-line-extract-emoji-boundary-multiple-whitespace () + "Multiple whitespace chars between colon and emoji are skipped." + (should (equal (wttrin--mode-line-extract-emoji "X: Z rest") + "Z"))) + +;;; Error Cases + +(ert-deftest test-wttrin--mode-line-extract-emoji-error-no-colon () + "String with no colon returns the placeholder \"?\"." + (should (equal (wttrin--mode-line-extract-emoji "no colon here") + "?"))) + +(ert-deftest test-wttrin--mode-line-extract-emoji-error-empty-string () + "Empty string returns the placeholder \"?\"." + (should (equal (wttrin--mode-line-extract-emoji "") + "?"))) + (provide 'test-wttrin--mode-line-helpers) ;;; test-wttrin--mode-line-helpers.el ends here |
