navidrome/model/lyrics_test.go
Deluan 8928378a57 refactor(lyrics): colocate and unexport cue-normalization helpers
Move the cue-normalization machinery out of lyrics.go into a dedicated
lyrics_normalize.go (with lyrics_normalize_test.go), leaving lyrics.go to hold
just the shared lyric types and their methods. lyrics.go was mixing the domain
type/contract definitions with format-agnostic post-processing.

Unexport normalizeLyrics, normalizeCueLines, and normalizeLineTiming: they have
no callers outside the model package, so they should not be part of its public
API. NormalizeCueEnds stays exported because the Subsonic enhanced-lyrics
serializer (server/subsonic/lyrics.go) resolves cue ends per agent group while
building the response; that is the only legitimate cross-package caller.

Also includes a small no-op robustness tweak in parseLRC: len(times) == 0
instead of times == nil (equivalent here, more idiomatic).

No behavior change.
2026-06-19 17:18:08 -04:00

69 lines
1.8 KiB
Go

package model
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Lyrics.EffectiveKind", func() {
It("defaults a blank kind to main", func() {
Expect(Lyrics{}.EffectiveKind()).To(Equal(LyricKindMain))
Expect(Lyrics{Kind: " "}.EffectiveKind()).To(Equal(LyricKindMain))
})
It("returns the kind as-is when set", func() {
Expect(Lyrics{Kind: LyricKindTranslation}.EffectiveKind()).To(Equal(LyricKindTranslation))
})
})
var _ = Describe("Lyrics.IsMainKind", func() {
It("is true for a blank (untyped) kind", func() {
Expect(Lyrics{}.IsMainKind()).To(BeTrue())
})
It("is true for the main kind", func() {
Expect(Lyrics{Kind: LyricKindMain}.IsMainKind()).To(BeTrue())
})
It("is false for translation and pronunciation kinds", func() {
Expect(Lyrics{Kind: LyricKindTranslation}.IsMainKind()).To(BeFalse())
Expect(Lyrics{Kind: LyricKindPronunciation}.IsMainKind()).To(BeFalse())
})
})
var _ = Describe("LyricList.Main", func() {
It("returns false when the list is empty", func() {
_, ok := LyricList{}.Main()
Expect(ok).To(BeFalse())
})
It("returns the main-kind entry when present", func() {
list := LyricList{
{Kind: LyricKindTranslation, Lang: "en"},
{Kind: LyricKindMain, Lang: "xxx"},
}
main, ok := list.Main()
Expect(ok).To(BeTrue())
Expect(main.Kind).To(Equal(LyricKindMain))
})
It("falls back to the first entry when no main kind exists", func() {
list := LyricList{
{Kind: LyricKindTranslation, Lang: "en"},
{Kind: LyricKindPronunciation, Lang: "ja"},
}
main, ok := list.Main()
Expect(ok).To(BeTrue())
Expect(main.Lang).To(Equal("en"))
})
It("treats a blank kind as main", func() {
list := LyricList{
{Kind: LyricKindTranslation, Lang: "en"},
{Lang: "xxx"},
}
main, ok := list.Main()
Expect(ok).To(BeTrue())
Expect(main.Lang).To(Equal("xxx"))
})
})