pvr: add options and support for anime (#17)
* pvr: begin adding options * pvr: add ability to configure add behaviour via config * pvr: add skip_anime * pvr: do not continue processing item if lookup failed or add to pvr failed
This commit is contained in:
@@ -20,3 +20,18 @@ func Atof64(val string, defaultVal float64) float64 {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func StringOrDefault(val string, defaultVal string) string {
|
||||
if val == "" {
|
||||
return defaultVal
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func BoolOrDefault(val *bool, defaultVal bool) bool {
|
||||
if val == nil {
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
return *val
|
||||
}
|
||||
|
||||
@@ -81,3 +81,39 @@ func TestAtoi(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolOrDefault(t *testing.T) {
|
||||
type args struct {
|
||||
val *bool
|
||||
defaultVal bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "expect default",
|
||||
args: args{
|
||||
val: nil,
|
||||
defaultVal: true,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "expect value",
|
||||
args: args{
|
||||
val: new(bool),
|
||||
defaultVal: true,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := BoolOrDefault(tt.args.val, tt.args.defaultVal); got != tt.want {
|
||||
t.Errorf("BoolOrDefault() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
12
util/slice.go
Normal file
12
util/slice.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package util
|
||||
|
||||
import "strings"
|
||||
|
||||
func StringSliceContains(slice []string, val string) bool {
|
||||
for _, s := range slice {
|
||||
if strings.EqualFold(s, val) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
39
util/slice_test.go
Normal file
39
util/slice_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStringSliceContains(t *testing.T) {
|
||||
type args struct {
|
||||
slice []string
|
||||
val string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "expect true",
|
||||
args: args{
|
||||
slice: []string{"tes", "Test"},
|
||||
val: "test",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "expect false",
|
||||
args: args{
|
||||
slice: []string{"tes", "Test"},
|
||||
val: "testing",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := StringSliceContains(tt.args.slice, tt.args.val); got != tt.want {
|
||||
t.Errorf("StringSliceContains() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user