Files
silo-server/internal/naming/folderid_test.go
383973ec22 feat(metadata): improve match accuracy and localized titles (#461)
* feat(metadata): improve match accuracy and localized titles

* fix(metadata): address matching review findings

* test(catalog): align empty alias snapshot scope

---------

Co-authored-by: Quick104 <31828688+Quick104@users.noreply.github.com>
2026-07-24 12:02:52 -04:00

78 lines
2.8 KiB
Go

package naming
import "testing"
func TestParseFolderIDs_BracketedBareImdb(t *testing.T) {
cases := []struct {
name, folder, wantImdb string
}{
{"square brackets", "17 Blocks (2021) [tt10011226]", "tt10011226"},
{"curly braces", "Some Show {tt1234567}", "tt1234567"},
{"8-digit tt", "Movie (2024) [tt12345678]", "tt12345678"},
{"9-digit tt", "Movie (2024) [tt123456789]", "tt123456789"},
{"10-digit tt", "Movie (2024) [tt1234567890]", "tt1234567890"},
{"parentheses production pattern", "10 Tricks (2022) (tt0473100) [WEBDL-1080p.AAC.h264.GNOME].mp4", "tt0473100"},
}
for _, c := range cases {
got := ParseFolderIDs(c.folder)
if got == nil || got.ImdbID != c.wantImdb {
t.Errorf("%s: ParseFolderIDs(%q) = %+v, want ImdbID=%q", c.name, c.folder, got, c.wantImdb)
}
}
// must NOT change existing behavior:
if got := ParseFolderIDs("Movie [imdb-tt1375666]"); got == nil || got.ImdbID != "tt1375666" {
t.Errorf("structured imdb regressed: %+v", got)
}
if got := ParseFolderIDs("Some Movie (2020) [BB]"); got != nil {
t.Errorf("non-tt bracket tag must not parse as id, got %+v", got)
}
if got := ParseFolderIDs("17 Blocks (2021)"); got != nil {
t.Errorf("no-id folder must return nil, got %+v", got)
}
}
func TestParseStructuredFolderIDs_ParenthesizedProviderIDs(t *testing.T) {
tests := []struct {
name string
want FolderIDHints
}{
{"Movie (imdb-tt1375666)", FolderIDHints{ImdbID: "tt1375666"}},
{"Movie (tmdb-27205)", FolderIDHints{TmdbID: "27205"}},
{"Show (tvdbid-81189)", FolderIDHints{TvdbID: "81189"}},
}
for _, tt := range tests {
got := ParseStructuredFolderIDs(tt.name)
if got == nil || *got != tt.want {
t.Errorf("ParseStructuredFolderIDs(%q) = %+v, want %+v", tt.name, got, tt.want)
}
}
for _, invalid := range []string{
"Movie (tt123)", "Movie (tt12345678901)", "Movie (tmdb-12x)",
"Movie (imdb-1234567)", "Movie [tmdb-123)", "Movie {tt1234567]",
"Movie (tmdb-0)", "Show (tvdb-000)", "Movie (tt0000000)",
"Movie (imdb-tt0000000)", "District 9", "Beverly Hills 90210",
} {
if got := ParseStructuredFolderIDs(invalid); got != nil {
t.Errorf("ParseStructuredFolderIDs(%q) = %+v, want nil", invalid, got)
}
}
}
func TestParseStructuredFolderIDs_BracketedBareImdb(t *testing.T) {
got := ParseStructuredFolderIDs("17 Blocks (2021) [tt10011226]")
if got == nil || got.ImdbID != "tt10011226" {
t.Fatalf("ParseStructuredFolderIDs bare imdb = %+v, want ImdbID tt10011226", got)
}
got = ParseStructuredFolderIDs("Some Movie {tmdb-12345} [tt7654321]")
if got == nil || got.TmdbID != "12345" || got.ImdbID != "tt7654321" {
t.Fatalf("ParseStructuredFolderIDs mixed ids = %+v, want tmdb+imdb", got)
}
got = ParseStructuredFolderIDs("Some Movie [imdb-tt1375666] [tt7654321]")
if got == nil || got.ImdbID != "tt1375666" {
t.Fatalf("structured imdb should win over bare imdb, got %+v", got)
}
}