aboutsummaryrefslogtreecommitdiff
path: root/tests/test-music-config--m3u-labels.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--m3u-labels.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--m3u-labels.el')
-rw-r--r--tests/test-music-config--m3u-labels.el62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test-music-config--m3u-labels.el b/tests/test-music-config--m3u-labels.el
new file mode 100644
index 00000000..02f328cd
--- /dev/null
+++ b/tests/test-music-config--m3u-labels.el
@@ -0,0 +1,62 @@
+;;; test-music-config--m3u-labels.el --- Tests for #EXTINF label extraction -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;; Author: Craig Jennings <c@cjennings.net>
+;;
+;;; Commentary:
+;; Unit tests for `cj/music--m3u-labels': parse .m3u text into an alist of
+;; (stream-url . #EXTINF-label) pairs. This is the pure core that lets a url
+;; track resolve to its station name (the label written at creation) instead
+;; of the raw stream URL.
+;;
+;;; 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)
+
+(ert-deftest test-music-config--m3u-labels-normal-single ()
+ "Normal: one #EXTINF + url pair yields one (url . label) cons."
+ (let ((text "#EXTM3U\n#EXTINF:1,SomaFM Groove Salad\nhttps://ice6.somafm.com/gs\n"))
+ (should (equal (cj/music--m3u-labels text)
+ '(("https://ice6.somafm.com/gs" . "SomaFM Groove Salad"))))))
+
+(ert-deftest test-music-config--m3u-labels-normal-uuid-line-between ()
+ "Normal: a #RADIOBROWSERUUID line between #EXTINF and the url is skipped."
+ (let ((text (concat "#EXTM3U\n#EXTINF:1,Jazz24\n"
+ "#RADIOBROWSERUUID:abc-123\nhttps://jazz.example/live\n")))
+ (should (equal (cj/music--m3u-labels text)
+ '(("https://jazz.example/live" . "Jazz24"))))))
+
+(ert-deftest test-music-config--m3u-labels-normal-multiple ()
+ "Normal: multiple stations each yield their own pair."
+ (let ((text (concat "#EXTM3U\n"
+ "#EXTINF:1,Station A\nhttps://a.example/1\n"
+ "#EXTINF:-1,Station B\nhttps://b.example/2\n")))
+ (should (equal (cj/music--m3u-labels text)
+ '(("https://a.example/1" . "Station A")
+ ("https://b.example/2" . "Station B"))))))
+
+(ert-deftest test-music-config--m3u-labels-boundary-url-without-extinf ()
+ "Boundary: a bare url with no preceding #EXTINF produces no pair."
+ (let ((text "#EXTM3U\nhttps://plain.example/stream\n"))
+ (should (null (cj/music--m3u-labels text)))))
+
+(ert-deftest test-music-config--m3u-labels-boundary-empty ()
+ "Boundary: empty text yields nil."
+ (should (null (cj/music--m3u-labels ""))))
+
+(ert-deftest test-music-config--m3u-labels-boundary-comma-in-name ()
+ "Boundary: a comma inside the label is preserved (split on the first only)."
+ (let ((text "#EXTINF:1,Radio, the Good Kind\nhttps://x.example/s\n"))
+ (should (equal (cj/music--m3u-labels text)
+ '(("https://x.example/s" . "Radio, the Good Kind"))))))
+
+(provide 'test-music-config--m3u-labels)
+;;; test-music-config--m3u-labels.el ends here