fix: address code review findings
This commit is contained in:
@@ -16,13 +16,13 @@ import (
|
||||
var (
|
||||
bracketRe = regexp.MustCompile(`\[[^\]]*\]`)
|
||||
parenRe = regexp.MustCompile(`\([^)]*\)`)
|
||||
yearRe = regexp.MustCompile(`\b(1[0-9]{3}|2[0-9]{3})\b`)
|
||||
yearRe = regexp.MustCompile(`\b[0-9]{4}\b`)
|
||||
spaceRe = regexp.MustCompile(`\s+`)
|
||||
// bareYearRe matches a title that is *only* a single year (with optional
|
||||
// surrounding whitespace), e.g. "1989" or "2112". Used to decide whether a
|
||||
// title that collapses entirely to a year should keep it (so it matches
|
||||
// itself) or be treated as a distinct reissue that must collapse to empty.
|
||||
bareYearRe = regexp.MustCompile(`^\s*(1[0-9]{3}|2[0-9]{3})\s*$`)
|
||||
bareYearRe = regexp.MustCompile(`^\s*[0-9]{4}\s*$`)
|
||||
)
|
||||
|
||||
// NormalizeString normalizes a string for fuzzy matching by:
|
||||
@@ -46,7 +46,7 @@ func NormalizeString(s string) string {
|
||||
// Remove parenthesized content (e.g., (Deluxe), (Remastered))
|
||||
s = parenRe.ReplaceAllString(s, "")
|
||||
|
||||
// Remove years (4-digit numbers between 1000-2999). If stripping the year
|
||||
// Remove years (any 4-digit number). If stripping the year
|
||||
// empties the entire string, decide what to keep:
|
||||
// - A bare year title (e.g. "1989", "2112") has no other words, so keep
|
||||
// the year so it can still match itself (the user owns that album).
|
||||
|
||||
@@ -48,8 +48,17 @@ func TestNormalizeString_Basic(t *testing.T) {
|
||||
// the bare year (it falsely matched "1989" before). It collapses to empty.
|
||||
{"1989 [2020]", ""},
|
||||
{"1989 2020", ""},
|
||||
{"3000 2000", "3000"},
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user