Files
mal/integrations/jikan/relations_test.go

73 lines
1.7 KiB
Go

package jikan
import "testing"
func runBoolCases(t *testing.T, tests []struct {
name string
input string
want bool
}, fn func(string) bool) {
t.Helper()
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
got := fn(testCase.input)
if got != testCase.want {
t.Fatalf("expected %v, got %v", testCase.want, got)
}
})
}
}
func TestIsAllowedWatchOrderType(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{name: "tv", input: "tv", want: true},
{name: "movie", input: "movie", want: true},
{name: "case and whitespace", input: " TV ", want: true},
{name: "tv special", input: "tv special", want: false},
{name: "ova", input: "ova", want: false},
{name: "empty", input: "", want: false},
}
runBoolCases(t, tests, isAllowedWatchOrderType)
}
func TestWatchOrderTypeLabel(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{name: "tv", input: "tv", want: "TV"},
{name: "movie", input: "movie", want: "Movie"},
{name: "trimmed passthrough", input: " tv special ", want: "tv special"},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
got := watchOrderTypeLabel(testCase.input)
if got != testCase.want {
t.Fatalf("expected %q, got %q", testCase.want, got)
}
})
}
}
func TestAllowedWatchOrderTypeFromDataset(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{name: "label tv", input: "TV", want: true},
{name: "label movie", input: "Movie", want: true},
{name: "label special", input: "Special", want: false},
}
runBoolCases(t, tests, isAllowedWatchOrderType)
}