Comment blocks in cmd/minstrel and 30 smaller internal packages, rewritten
to rule 32's standard with each citation read in context: task, milestone
and rule ids go, and so do the stories they were attached to ("used to",
"Before #N", measurements from one install, quotes, pointers to Fabled
Librarian's records and to docs/superpowers files that are not in the
repo). Where a story wrapped a real constraint, the constraint stays as a
present-tense fact.
Comments that had gone stale are corrected:
- taste.Config: the tuned values are overlaid by internal/recsettings;
it is no longer "a later follow-up".
- StorageConfig: the data dir holds art, caches and the stream secret,
not only playlist covers.
- the Subsonic album list and getUser comments describe what they do
today rather than a milestone that would change it.
Checked: the non-comment token stream of every changed file matches
HEAD, and gofmt -l is empty.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package subsonic
|
|
|
|
import (
|
|
"encoding/json"
|
|
"encoding/xml"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/library"
|
|
)
|
|
|
|
// OpenSubsonic's replayGain is an object in JSON and an element with
|
|
// attributes in XML. Clients parse both, so both are pinned.
|
|
func TestSongRef_ReplayGainEncodesForBothFormats(t *testing.T) {
|
|
gain, peak := float32(-4.5), float32(0.8913)
|
|
tr := dbq.Track{Title: "Song", FilePath: "/m/a.flac", FileFormat: "flac"}
|
|
s := songRef(tr, "Album", "Artist", library.ReplayGain{TrackGain: &gain, TrackPeak: &peak})
|
|
|
|
b, err := json.Marshal(s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m map[string]any
|
|
if err := json.Unmarshal(b, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rg, ok := m["replayGain"].(map[string]any)
|
|
if !ok {
|
|
t.Fatalf("JSON has no replayGain object: %s", b)
|
|
}
|
|
if rg["trackGain"] != -4.5 || rg["trackPeak"] == nil {
|
|
t.Errorf("JSON replayGain = %v, want trackGain -4.5 and a trackPeak", rg)
|
|
}
|
|
if _, ok := rg["albumGain"]; ok {
|
|
t.Errorf("JSON replayGain carries albumGain with no album value: %v", rg)
|
|
}
|
|
|
|
x, err := xml.Marshal(s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(x), `<replayGain trackGain="-4.5" trackPeak="0.8913"></replayGain>`) {
|
|
t.Errorf("XML lacks the replayGain element: %s", x)
|
|
}
|
|
}
|
|
|
|
func TestSongRef_NoReplayGainWhenUnmeasured(t *testing.T) {
|
|
s := songRef(dbq.Track{Title: "Song", FilePath: "/m/a.mp3"}, "Album", "Artist", library.ReplayGain{})
|
|
if s.ReplayGain != nil {
|
|
t.Fatalf("unmeasured song carries replayGain %+v", s.ReplayGain)
|
|
}
|
|
b, _ := json.Marshal(s)
|
|
x, _ := xml.Marshal(s)
|
|
if strings.Contains(string(b), "replayGain") || strings.Contains(string(x), "replayGain") {
|
|
t.Errorf("unmeasured song encodes replayGain: %s / %s", b, x)
|
|
}
|
|
}
|