gobbler/categorize/tv/show_test.go

77 lines
2.1 KiB
Go

package tv
import (
"fmt"
"testing"
"github.com/ollien/gobbler/categorize/match"
"github.com/stretchr/testify/assert"
)
func TestFindShowFolder(t *testing.T) {
tt := []struct {
testName string
fileName string
folders []string
expectedFolder string
expectedError error
}{
{
"Single word show",
"Westworld.S02.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb",
[]string{"Arrested-Development", "Barry", "Westworld", "Brooklyn-Nine-Nine"},
"Westworld",
nil,
},
{
"Multi word show",
"Arrested.Development.S01E01.MULTi.1080p.WEB.x264-CiELOS",
[]string{"Arrested-Development", "Barry", "Westworld", "Brooklyn-Nine-Nine"},
"Arrested-Development",
nil,
},
{
"Does not over-match",
// "Arrested.Development"'s closest string (w.r.t leventhstein distance) is Westworld,
// which is obvioulsy not the same
"Arrested.Development.S01E01.MULTi.1080p.WEB.x264-CiELOS",
[]string{"Barry", "Westworld", "Brooklyn-Nine-Nine", "The-IT-Crowd"},
"",
match.ErrNoMatches,
},
{
"Does not use single-character prefixes as a reference",
"SpongeBob.SquarePants.S03.iT.WEB-DL.AAC2.0.H.264-NOGR",
[]string{"The-Good-Place", "Stranger-Things", "Brooklyn-Nine-Nine", "The-IT-Crowd"},
"",
match.ErrNoMatches,
},
{
"A match with a non-meaningful prefix ('the') should not match",
"The.Amazing.Spider-Man.1977.S01.VHSRip",
[]string{"The-Good-Place", "The-Simpsons", "Stranger-Things", "Brooklyn-Nine-Nine", "The-IT-Crowd"},
"",
match.ErrNoMatches,
},
{
"A good match starting with 'the' should still match",
"The.Simpsons.S06.720p.DSNP.WEB-DL.DDP5.1.H.264-MZABI",
[]string{"The-Good-Place", "The-Simpsons", "Stranger-Things", "Brooklyn-Nine-Nine", "The-IT-Crowd"},
"The-Simpsons",
nil,
},
}
for _, test := range tt {
t.Run(test.testName, func(t *testing.T) {
foundFolder, err := FindShowFolder(test.fileName, test.folders)
if test.expectedError != nil {
assert.ErrorIs(t, err, test.expectedError, fmt.Sprintf("got show %q and error %q", foundFolder, err))
} else {
assert.Nil(t, err)
assert.Equal(t, test.expectedFolder, foundFolder)
}
})
}
}