Implemented proper index grouping

This commit is contained in:
Deluan
2016-03-01 17:50:05 -05:00
parent 9d6eb40f6f
commit c64a0f8242
4 changed files with 81 additions and 12 deletions
+61 -2
View File
@@ -3,10 +3,69 @@ package scanner
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/utils"
"github.com/deluan/gosonic/models"
"github.com/deluan/gosonic/tests"
)
func TestEmpty(t *testing.T) {
func TestCollectIndex(t *testing.T) {
tests.Init(t, false)
Convey("Missing tests", t, nil)
ig := utils.IndexGroups{"A":"A", "B":"B", "Tom":"Tom", "X":"X-Z"}
Convey("Simple Name", t, func() {
a := &models.Artist{Name: "Björk"}
artistIndex := make(map[string]tempIndex)
collectIndex(ig, a, artistIndex)
So(artistIndex, ShouldContainKey, "B")
So(artistIndex["B"], ShouldContainKey, "björk")
for _, k := range []string{"A", "Tom", "X-Z", "#"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name not in the index", t, func() {
a := &models.Artist{Name: "Kraftwerk"}
artistIndex := make(map[string]tempIndex)
collectIndex(ig, a, artistIndex)
So(artistIndex, ShouldContainKey, "#")
So(artistIndex["#"], ShouldContainKey, "kraftwerk")
for _, k := range []string{"A", "B", "Tom", "X-Z"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name starts with an article", t, func() {
a := &models.Artist{Name: "The The"}
artistIndex := make(map[string]tempIndex)
collectIndex(ig, a, artistIndex)
So(artistIndex, ShouldContainKey, "#")
So(artistIndex["#"], ShouldContainKey, "the")
for _, k := range []string{"A", "B", "Tom", "X-Z"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name match a multichar entry", t, func() {
a := &models.Artist{Name: "Tom Waits"}
artistIndex := make(map[string]tempIndex)
collectIndex(ig, a, artistIndex)
So(artistIndex, ShouldContainKey, "Tom")
So(artistIndex["Tom"], ShouldContainKey, "tom waits")
for _, k := range []string{"A", "B", "X-Z", "#"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
}