JSPF: Implemented export as loves and listens

This commit is contained in:
Philipp Wolfer 2025-05-01 15:10:00 +02:00
parent cfc3cd522d
commit a645ec5c78
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
6 changed files with 225 additions and 42 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -26,6 +26,7 @@ import (
"bytes"
"fmt"
"log"
"testing"
"time"
"go.uploadedlobster.com/scotty/pkg/jspf"
@ -38,7 +39,7 @@ func ExampleMusicBrainzTrackExtension() {
Tracks: []jspf.Track{
{
Title: "Oweynagat",
Extension: map[string]any{
Extension: jspf.ExtensionMap{
jspf.MusicBrainzTrackExtensionID: jspf.MusicBrainzTrackExtension{
AddedAt: time.Date(2023, 11, 24, 07, 47, 50, 0, time.UTC),
AddedBy: "scotty",
@ -72,3 +73,29 @@ func ExampleMusicBrainzTrackExtension() {
// }
// }
}
func TestExtensionMapGet(t *testing.T) {
ext := jspf.ExtensionMap{
jspf.MusicBrainzTrackExtensionID: jspf.MusicBrainzTrackExtension{
AddedAt: time.Date(2023, 11, 24, 07, 47, 50, 0, time.UTC),
AddedBy: "scotty",
},
}
var trackExt jspf.MusicBrainzTrackExtension
err := ext.Get(jspf.MusicBrainzTrackExtensionID, &trackExt)
if err != nil {
t.Fatal(err)
}
if trackExt.AddedBy != "scotty" {
t.Fatalf("expected 'scotty', got '%s'", trackExt.AddedBy)
}
}
func TestExtensionMapGetNotFound(t *testing.T) {
ext := jspf.ExtensionMap{}
var trackExt jspf.MusicBrainzTrackExtension
err := ext.Get(jspf.MusicBrainzTrackExtensionID, &trackExt)
if err == nil {
t.Fatal("expected ExtensionMap.Get to return an error")
}
}