mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 12:58:33 +02:00
Implemented ScrobblerLog.ParseIter
This commit is contained in:
parent
15755458e9
commit
3b9d07e6b5
2 changed files with 129 additions and 57 deletions
|
@ -44,7 +44,14 @@ Kraftwerk Trans-Europe Express The Hall of Mirrors 2 474 S 1260358000 385ba9e9-6
|
|||
Teeth Agency You Don't Have To Live In Pain Wolfs Jam 2 107 L 1260359404 1262beaf-19f8-4534-b9ed-7eef9ca8e83f
|
||||
`
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
var testScrobblerLogInvalid = `#AUDIOSCROBBLER/1.1
|
||||
#TZ/UNKNOWN
|
||||
#CLIENT/Rockbox sansaclipplus $Revision$
|
||||
Özcan Deniz Ses ve Ayrilik Sevdanin rengi (sipacik) byMrTurkey 5 306 L 1260342084
|
||||
Özcan Deniz Hediye 2@V@7 Bir Dudaktan 1 210 L
|
||||
`
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := bytes.NewBufferString(testScrobblerLog)
|
||||
result := scrobblerlog.ScrobblerLog{}
|
||||
|
@ -68,7 +75,7 @@ func TestParser(t *testing.T) {
|
|||
record4.MusicBrainzRecordingID)
|
||||
}
|
||||
|
||||
func TestParserIgnoreSkipped(t *testing.T) {
|
||||
func TestParseIgnoreSkipped(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := bytes.NewBufferString(testScrobblerLog)
|
||||
result := scrobblerlog.ScrobblerLog{}
|
||||
|
@ -81,7 +88,7 @@ func TestParserIgnoreSkipped(t *testing.T) {
|
|||
record4.MusicBrainzRecordingID)
|
||||
}
|
||||
|
||||
func TestParserFallbackTimezone(t *testing.T) {
|
||||
func TestParseFallbackTimezone(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := bytes.NewBufferString(testScrobblerLog)
|
||||
result := scrobblerlog.ScrobblerLog{
|
||||
|
@ -96,6 +103,29 @@ func TestParserFallbackTimezone(t *testing.T) {
|
|||
)
|
||||
}
|
||||
|
||||
func TestParseInvalid(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := bytes.NewBufferString(testScrobblerLogInvalid)
|
||||
result := scrobblerlog.ScrobblerLog{}
|
||||
err := result.Parse(data, true)
|
||||
assert.ErrorContains(err, "invalid record in scrobblerlog line 2")
|
||||
}
|
||||
|
||||
func TestParseIter(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := bytes.NewBufferString(testScrobblerLog)
|
||||
result := scrobblerlog.ScrobblerLog{}
|
||||
records := make([]scrobblerlog.Record, 0)
|
||||
for record, err := range result.ParseIter(data, false) {
|
||||
require.NoError(t, err)
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
assert.Len(records, 5)
|
||||
record1 := result.Records[0]
|
||||
assert.Equal("Ses ve Ayrilik", record1.AlbumName)
|
||||
}
|
||||
|
||||
func TestAppend(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
data := make([]byte, 0, 10)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue