aboutsummaryrefslogtreecommitdiff
path: root/tests/test-music-config--bar-fill.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-06 16:56:40 -0500
committerCraig Jennings <c@cjennings.net>2026-07-06 16:56:40 -0500
commit0a7afa70fa9c2c20771696b303c9cae4aa7c58a2 (patch)
tree8d97a9f3b8cba2ad97d808114e9a00edce903711 /tests/test-music-config--bar-fill.el
parentea8bbce911650515b88fd3a61fdb88186e550347 (diff)
downloaddotemacs-0a7afa70fa9c2c20771696b303c9cae4aa7c58a2.tar.gz
dotemacs-0a7afa70fa9c2c20771696b303c9cae4aa7c58a2.zip
feat(music): show station and track names, not stream URLs (fancy UI phase 1)
The EMMS playlist showed the raw stream URL for every radio track, so the buffer read like a debug log. This is phase 1 of the fancy player: real names, still plain text. It ships on its own and becomes the fallback for the image and GUI phases. I split the old cj/music--track-description into a pure, name-only cj/music--display-name that the header's Current line and the row renderer both call, so the two never drift. A url track resolves to its #EXTINF label (read once from all the playlist .m3u files into a cached map) or a tidied host. A file shows Artist - Title or its filename. The row renderer adds a dim nerd-icon glyph and the duration as right-aligned meta with an :align-to space, so it survives a window resize. The header line stays clean: just the name plus an on-air or duration suffix. The pure helpers carry the tests: display-name, tidy-host, m3u-labels, bar-fill, format-meta, Normal/Boundary/Error each (32 tests across four files). The glyph, the aligned meta, and the disk-backed name map are the thin composition, verified live against 44 real stations. The progress bar's visual and its live elapsed source come in phase 3. The bar-fill helper is the tested pure core it will feed. The full suite is green.
Diffstat (limited to 'tests/test-music-config--bar-fill.el')
-rw-r--r--tests/test-music-config--bar-fill.el63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-music-config--bar-fill.el b/tests/test-music-config--bar-fill.el
new file mode 100644
index 00000000..f6d8dac8
--- /dev/null
+++ b/tests/test-music-config--bar-fill.el
@@ -0,0 +1,63 @@
+;;; test-music-config--bar-fill.el --- Tests for progress-bar fill math -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;; Author: Craig Jennings <c@cjennings.net>
+;;
+;;; Commentary:
+;; Unit tests for `cj/music--bar-fill': the pure computation of how many cells
+;; of a WIDTH-cell progress bar are filled given ELAPSED and TOTAL seconds.
+;; A stream (no duration) is indeterminate; the live elapsed source (mpv) is
+;; wired in a later phase, so this helper only does the clamp-and-round math.
+;;
+;;; Code:
+
+(require 'ert)
+
+(defvar-keymap cj/custom-keymap :doc "Stub keymap for testing")
+
+(let ((emms-dir (car (file-expand-wildcards
+ (expand-file-name "elpa/emms-*" user-emacs-directory)))))
+ (when emms-dir (add-to-list 'load-path emms-dir)))
+
+(require 'emms)
+(require 'music-config)
+
+;;; Normal
+
+(ert-deftest test-music-config--bar-fill-normal-half ()
+ "Normal: halfway through fills half the cells."
+ (should (= (cj/music--bar-fill 30 60 20) 10)))
+
+(ert-deftest test-music-config--bar-fill-normal-quarter ()
+ "Normal: a quarter elapsed rounds to a quarter of the cells."
+ (should (= (cj/music--bar-fill 15 60 20) 5)))
+
+;;; Boundary
+
+(ert-deftest test-music-config--bar-fill-boundary-zero-elapsed ()
+ "Boundary: nothing elapsed fills no cells."
+ (should (= (cj/music--bar-fill 0 60 20) 0)))
+
+(ert-deftest test-music-config--bar-fill-boundary-full ()
+ "Boundary: elapsed equal to total fills every cell."
+ (should (= (cj/music--bar-fill 60 60 20) 20)))
+
+(ert-deftest test-music-config--bar-fill-boundary-over-clamps ()
+ "Boundary: elapsed past total clamps to full, never overflows."
+ (should (= (cj/music--bar-fill 90 60 20) 20)))
+
+(ert-deftest test-music-config--bar-fill-boundary-nil-elapsed ()
+ "Boundary: an unknown elapsed (nil) fills no cells."
+ (should (= (cj/music--bar-fill nil 60 20) 0)))
+
+;;; Error / indeterminate
+
+(ert-deftest test-music-config--bar-fill-indeterminate-nil-total ()
+ "Error: a stream (nil total) is indeterminate, not a cell count."
+ (should (eq (cj/music--bar-fill 30 nil 20) 'indeterminate)))
+
+(ert-deftest test-music-config--bar-fill-indeterminate-zero-total ()
+ "Error: a zero total is indeterminate rather than a divide-by-zero."
+ (should (eq (cj/music--bar-fill 30 0 20) 'indeterminate)))
+
+(provide 'test-music-config--bar-fill)
+;;; test-music-config--bar-fill.el ends here