From 830654d2a5af29d6df5d61d061417a1a7503ab42 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 6 Jul 2026 13:32:46 -0500 Subject: feat(music): radio-browser search command + keybinding (phase 2) I wired up the interactive side of the radio-browser lookup: cj/music-radio-search, bound to S in the EMMS playlist buffer (s stays emms-stop). It searches, lists the matches annotated with codec, bitrate, country, votes, and tags, and lets you pick several one at a time. Selection is a completing-read loop with a "[done]" sentinel that removes each pick from the pool, so a station name with a comma can't be mis-split. Each pick is written into the save directory (no-URL stations skipped and named, colliding filenames disambiguated by UUID), then the selection plays through mpv, interrupting whatever was on. The dedup and write-collect logic are unit-tested. The picker and playback are left to a manual check. --- tests/test-music-config--radio.el | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests') diff --git a/tests/test-music-config--radio.el b/tests/test-music-config--radio.el index 651e2cb7..b8ce5e30 100644 --- a/tests/test-music-config--radio.el +++ b/tests/test-music-config--radio.el @@ -136,5 +136,54 @@ (should (string-match-p "limit=30" u)) (should (string-match-p "/json/stations/search" u)))) +(declare-function cj/music-radio--candidates "music-config" (stations)) +(declare-function cj/music-radio--write-stations "music-config" (stations dir)) + +;;; --------------------------- candidates (dedup) ----------------------------- + +(ert-deftest test-music-radio-candidates-distinct () + "Normal: distinct station names produce distinct display keys mapping to their stations." + (let* ((stations '((:name "Jazz Radio" :codec "MP3" :bitrate 128) + (:name "Blues FM" :codec "AAC" :bitrate 64))) + (cands (cj/music-radio--candidates stations))) + (should (= (length cands) 2)) + (should (assoc "Jazz Radio" cands)) + (should (assoc "Blues FM" cands)))) + +(ert-deftest test-music-radio-candidates-same-name-disambiguated () + "Boundary: two stations with the same name get distinct display keys." + (let* ((stations '((:name "Jazz Radio" :codec "MP3" :bitrate 128 :stationuuid "a") + (:name "Jazz Radio" :codec "OGG" :bitrate 192 :stationuuid "b"))) + (cands (cj/music-radio--candidates stations)) + (keys (mapcar #'car cands))) + (should (= (length cands) 2)) + (should (= (length (delete-dups (copy-sequence keys))) 2)))) + +;;; --------------------------- write-stations --------------------------------- + +(ert-deftest test-music-radio-write-stations-writes-and-skips () + "Normal + Error: a station with a URL is written; one with no URL is skipped and named." + (let ((dir (make-temp-file "radio-write-" t))) + (unwind-protect + (let* ((stations (list (test-music-radio--first) + '(:name "No URL Here" :url_resolved "" :url ""))) + (result (cj/music-radio--write-stations stations dir))) + (should (= (length (plist-get result :written)) 1)) + (should (member "No URL Here" (plist-get result :skipped))) + (should (file-exists-p (car (plist-get result :written))))) + (delete-directory dir t)))) + +(ert-deftest test-music-radio-write-stations-collision-writes-two-files () + "Boundary: two same-named stations in one run write two distinct files, no overwrite." + (let ((dir (make-temp-file "radio-write-" t))) + (unwind-protect + (let* ((stations '((:name "Same Name" :url_resolved "http://a.test/s" :stationuuid "aaaa1111") + (:name "Same Name" :url_resolved "http://b.test/s" :stationuuid "bbbb2222"))) + (result (cj/music-radio--write-stations stations dir)) + (written (plist-get result :written))) + (should (= (length written) 2)) + (should-not (equal (nth 0 written) (nth 1 written)))) + (delete-directory dir t)))) + (provide 'test-music-config--radio) ;;; test-music-config--radio.el ends here -- cgit v1.2.3