quintodrome/scanner/scanner_test.go

72 lines
1.8 KiB
Go
Raw Normal View History

package scanner
2016-03-01 08:43:55 -09:00
import (
2016-03-02 05:07:24 -09:00
"github.com/deluan/gosonic/domain"
2016-03-02 09:18:39 -09:00
"github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/utils"
. "github.com/smartystreets/goconvey/convey"
"testing"
2016-03-01 08:43:55 -09:00
)
2016-03-01 13:50:05 -09:00
func TestCollectIndex(t *testing.T) {
tests.Init(t, false)
2016-03-02 09:18:39 -09:00
ig := utils.IndexGroups{"A": "A", "B": "B", "Tom": "Tom", "X": "X-Z"}
2016-03-01 08:43:55 -09:00
2016-03-01 13:50:05 -09:00
Convey("Simple Name", t, func() {
2016-03-02 05:07:24 -09:00
a := &domain.Artist{Name: "Björk"}
2016-03-01 13:50:05 -09:00
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() {
2016-03-02 05:07:24 -09:00
a := &domain.Artist{Name: "Kraftwerk"}
2016-03-01 13:50:05 -09:00
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() {
2016-03-02 05:07:24 -09:00
a := &domain.Artist{Name: "The The"}
2016-03-01 13:50:05 -09:00
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() {
2016-03-02 05:07:24 -09:00
a := &domain.Artist{Name: "Tom Waits"}
2016-03-01 13:50:05 -09:00
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)
}
})
}