aboutsummaryrefslogtreecommitdiff
path: root/tests/test-music-config--tidy-host.el
blob: 92b104a6a2f9370e73eba7b6a5b347abedea0abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;; test-music-config--tidy-host.el --- Tests for stream-URL host tidying -*- coding: utf-8; lexical-binding: t; -*-
;;
;; Author: Craig Jennings <c@cjennings.net>
;;
;;; Commentary:
;; Unit tests for `cj/music--tidy-host': reduce a stream URL to a readable host
;; label (scheme dropped, a leading "www." removed), used as the last-resort
;; display name for a url track with no #EXTINF label.
;;
;;; 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--tidy-host-normal ()
  "Normal: scheme and path are dropped, host kept."
  (should (string= (cj/music--tidy-host "https://ice6.somafm.com/groovesalad-256-mp3")
                   "somafm.com")))

(ert-deftest test-music-config--tidy-host-normal-http ()
  "Normal: plain http host with a port keeps the host, drops the port."
  (should (string= (cj/music--tidy-host "http://stream.example.org:8000/live")
                   "example.org")))

(ert-deftest test-music-config--tidy-host-boundary-strip-www ()
  "Boundary: a leading www. is stripped."
  (should (string= (cj/music--tidy-host "https://www.radioparadise.com/m3u/mp3-128.m3u")
                   "radioparadise.com")))

(ert-deftest test-music-config--tidy-host-boundary-bare-domain ()
  "Boundary: a two-label domain is returned unchanged."
  (should (string= (cj/music--tidy-host "http://somafm.com/") "somafm.com")))

(ert-deftest test-music-config--tidy-host-error-not-a-url ()
  "Error: a non-URL string is returned as-is rather than erroring."
  (should (string= (cj/music--tidy-host "not a url") "not a url")))

(provide 'test-music-config--tidy-host)
;;; test-music-config--tidy-host.el ends here