Files
NaviWatcher/internal/normalize/normalize_test.go

100 lines
3.2 KiB
Go

package normalize
import "testing"
func TestNormalizeString_Basic(t *testing.T) {
tests := []struct {
input string
expected string
}{
// Lowercase conversion
{"DARK SIDE OF THE MOON", "dark side of the moon"},
// Special character removal
{"Dark Side of the Moon!", "dark side of the moon"},
{"Dark-Side-of-the-Moon", "dark side of the moon"},
{"Dark_Side_of_the_Moon", "dark side of the moon"},
// Bracket removal
{"Dark Side of the Moon [Deluxe Edition]", "dark side of the moon"},
{"Dark Side of the Moon [Remastered 2020]", "dark side of the moon"},
{"Album [2023 Remix]", "album"},
// Parenthesis removal
{"Dark Side of the Moon (Deluxe)", "dark side of the moon"},
{"Album (Remastered)", "album"},
// Year removal
{"Dark Side of the Moon 1973", "dark side of the moon"},
{"Album 2020 Remastered", "album remastered"},
// Space collapsing
{"Dark Side of the Moon", "dark side of the moon"},
// Trim
{" Dark Side of the Moon ", "dark side of the moon"},
// Combined
{"The Dark Side of the Moon [2011 Remaster] (Deluxe Edition)", "the dark side of the moon"},
// Empty
{"", ""},
// Only special chars
{"!@#$%^&*()", ""},
// Digits that are not years should stay
{"30 Seconds to Mars", "30 seconds to mars"},
{"1941 - The Greatest Hits", "the greatest hits"},
// Year-only title is preserved (not collapsed to empty) so it can still match
{"1989", "1989"},
{"2112", "2112"},
// A year-plus-suffix title collapses to empty: it is a distinct release
// group (e.g. "1989 (Deluxe)") and must NOT match a bare "1989".
{"1989 (Deluxe)", ""},
{"1989 [Deluxe Edition]", ""},
{"2112 (Remastered)", ""},
// Regression: a year with a bracketed/suffixed year must NOT collapse to
// the bare year (it falsely matched "1989" before). It collapses to empty.
{"1989 [2020]", ""},
{"1989 2020", ""},
// Both tokens are years → both stripped → empty (no album words remain).
{"3000 2000", ""},
{"1989 RMX", "rmx"},
// Regression: year regex must cover ALL 4-digit years, not just 1000-2999.
// A reissue of a year-titled album outside that range must still collapse
// to empty so it is correctly reported as missing and does NOT falsely
// match a bare year-titled local album.
{"3000", "3000"},
{"3000 (Remastered)", ""},
{"3010 [Deluxe Edition]", ""},
{"4000 (Remastered)", ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := NormalizeString(tt.input)
if got != tt.expected {
t.Errorf("NormalizeString(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}
func TestNormalizeArtistName(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"Pink Floyd", "pink floyd"},
{"The Beatles", "beatles"},
{"A Perfect Circle", "perfect circle"},
{"An Orchestra", "orchestra"},
{" The Who ", "who"},
{"THE WHO", "who"},
// No stripping needed
{"Radiohead", "radiohead"},
// Already stripped
{"Beatles", "beatles"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := NormalizeArtistName(tt.input)
if got != tt.expected {
t.Errorf("NormalizeArtistName(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}