feat: idnorm and playlist support
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeChannelID(t *testing.T) {
|
||||
cases := []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"Italia 1", "italia1"},
|
||||
{"Italia 1.it", "italia1"},
|
||||
{"italia 1", "italia1"},
|
||||
{" Italia 1 ", "italia1"},
|
||||
{"Italia-1", "italia1"},
|
||||
{"Rai 1", "rai1"},
|
||||
{"Rai 1.it", "rai1"},
|
||||
{"ESPN.com", "espn"},
|
||||
{"Channel 4.uk", "channel4"},
|
||||
|
||||
// Quality-marker stripping — open-epg shape vs. playlist shape.
|
||||
{"Italia 1 HD.it", "italia1"},
|
||||
{"Rai 1 HD.it", "rai1"},
|
||||
{"TV8 HD.it", "tv8"},
|
||||
{"NOVE HD", "nove"},
|
||||
{"NOVE HD.it", "nove"},
|
||||
{"20Mediaset HD.it", "20mediaset"},
|
||||
{"Italia 1 Full HD", "italia1"},
|
||||
{"Italia 1 4K", "italia1"},
|
||||
|
||||
// Channels that legitimately contain "HD" — no stripping unless trailing.
|
||||
{"HD", "hd"},
|
||||
{"HD Network", "hdnetwork"},
|
||||
{"Sky HD Italia", "skyhditalia"},
|
||||
|
||||
{"", ""},
|
||||
{" ", ""},
|
||||
{".com", ""},
|
||||
{"Foo.Bar", "foobar"}, // ".bar" is not a known suffix
|
||||
{"foo.it.something", "fooitsomething"}, // mid-string ".it" is NOT stripped — only trailing suffix
|
||||
{"Caffè 24", "caffè24"}, // unicode letter survives
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
if got := normalizeChannelID(c.in); got != c.want {
|
||||
t.Errorf("normalizeChannelID(%q) = %q, want %q", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildIDMap(t *testing.T) {
|
||||
ids := []string{"Italia 1", "Rai 1", "Italia 1", "", " "}
|
||||
m := buildIDMap(ids)
|
||||
|
||||
if got, want := m["italia1"], "Italia 1"; got != want {
|
||||
t.Errorf("italia1 -> %q, want %q", got, want)
|
||||
}
|
||||
if got, want := m["rai1"], "Rai 1"; got != want {
|
||||
t.Errorf("rai1 -> %q, want %q", got, want)
|
||||
}
|
||||
if len(m) != 2 {
|
||||
t.Errorf("len(m) = %d, want 2 (empties dropped, dupes deduped)", len(m))
|
||||
}
|
||||
|
||||
// First occurrence wins for the canonical mapping.
|
||||
first := buildIDMap([]string{"Italia 1", "italia 1"})
|
||||
if first["italia1"] != "Italia 1" {
|
||||
t.Errorf("first-wins broken: got %q", first["italia1"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user