Implemented proper index grouping
This commit is contained in:
+61
-2
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user