media: merge tvdb and trakt languages

This commit is contained in:
James Bayliss
2021-02-24 18:57:39 +00:00
parent cea77e7849
commit bf23d93209
3 changed files with 89 additions and 1 deletions

View File

@@ -10,3 +10,34 @@ func StringSliceContains(slice []string, val string) bool {
}
return false
}
func StringSliceMergeUnique(existingSlice []string, mergeSlice []string) []string {
// add existing
data := make([]string, 0)
for _, es := range existingSlice {
if es == "" {
continue
}
data = append(data, es)
}
// add merge items (unique)
for _, ms := range mergeSlice {
if ms == "" {
continue
}
merge := true
for _, es := range data {
if strings.EqualFold(es, ms) {
merge = false
break
}
}
if merge {
data = append(data, ms)
}
}
return data
}

View File

@@ -1,6 +1,9 @@
package util
import "testing"
import (
"reflect"
"testing"
)
func TestStringSliceContains(t *testing.T) {
type args struct {
@@ -37,3 +40,55 @@ func TestStringSliceContains(t *testing.T) {
})
}
}
func TestStringSliceMergeUnique(t *testing.T) {
type args struct {
existingSlice []string
mergeSlice []string
}
tests := []struct {
name string
args args
want []string
}{
{
name: "no change",
args: args{
existingSlice: []string{"test", "test2"},
mergeSlice: []string{"test", "Test2"},
},
want: []string{"test", "test2"},
},
{
name: "no change empty",
args: args{
existingSlice: []string{},
mergeSlice: []string{},
},
want: []string{},
},
{
name: "with change",
args: args{
existingSlice: []string{"test", "test2"},
mergeSlice: []string{"test", "Test2", "test3"},
},
want: []string{"test", "test2", "test3"},
},
{
name: "with change no empty",
args: args{
existingSlice: []string{"", "en"},
mergeSlice: []string{"fr", "", "en"},
},
want: []string{"en", "fr"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StringSliceMergeUnique(tt.args.existingSlice, tt.args.mergeSlice); !reflect.DeepEqual(got, tt.want) {
t.Errorf("StringSliceMergeUnique() = %v, want %v", got, tt.want)
}
})
}
}