test(lyrics): add direct coverage for NormalizeCueEnds

NormalizeCueEnds is exported and carries the most intricate logic in the
normalization cluster (fill-from-next, fill-from-fallback, both clamps, and the
all-or-none clear), but was only exercised transitively. Add a focused spec
covering each branch plus the empty-input and no-mutation guarantees, bringing
the function to 100% coverage.
This commit is contained in:
Deluan 2026-06-19 17:22:46 -04:00
commit a2577ad9b9

View file

@ -31,3 +31,90 @@ var _ = Describe("normalizeCueLines", func() {
Expect(lines[0].Cue[1].End).To(BeNil())
})
})
var _ = Describe("NormalizeCueEnds", func() {
// p returns a fresh pointer so cases don't share *int64 state.
p := func(v int64) *int64 { return &v }
// endsOf extracts the resolved end times (nil-safe) for compact assertions.
endsOf := func(cues []Cue) []*int64 {
out := make([]*int64, len(cues))
for i := range cues {
out[i] = cues[i].End
}
return out
}
It("returns the input as-is when empty", func() {
Expect(NormalizeCueEnds(nil, p(1000))).To(BeNil())
Expect(NormalizeCueEnds([]Cue{}, p(1000))).To(BeEmpty())
})
It("fills a missing end from the next cue's start", func() {
cues := []Cue{
{Start: p(1000)},
{Start: p(1500)},
}
out := NormalizeCueEnds(cues, p(3000))
Expect(endsOf(out)).To(Equal([]*int64{p(1500), p(3000)}))
})
It("fills the last cue's missing end from fallbackEnd", func() {
cues := []Cue{
{Start: p(1000), End: p(1200)},
{Start: p(1500)},
}
out := NormalizeCueEnds(cues, p(3000))
Expect(endsOf(out)).To(Equal([]*int64{p(1200), p(3000)}))
})
It("clamps an end that overruns the next cue's start", func() {
cues := []Cue{
{Start: p(1000), End: p(9999)},
{Start: p(1500), End: p(2000)},
}
out := NormalizeCueEnds(cues, p(3000))
Expect(endsOf(out)).To(Equal([]*int64{p(1500), p(2000)}))
})
It("clamps an end that precedes the cue's own start", func() {
cues := []Cue{
{Start: p(1000), End: p(500)},
}
out := NormalizeCueEnds(cues, p(3000))
Expect(endsOf(out)).To(Equal([]*int64{p(1000)}))
})
It("clears all ends when any cue still lacks one (all-or-none)", func() {
// The last cue has no end and there is no fallback, so it stays nil and
// every end in the group is cleared.
cues := []Cue{
{Start: p(1000), End: p(1200)},
{Start: p(1500)},
}
out := NormalizeCueEnds(cues, nil)
Expect(endsOf(out)).To(Equal([]*int64{nil, nil}))
})
It("does not mutate the input slice", func() {
cues := []Cue{
{Start: p(1000)},
{Start: p(1500)},
}
_ = NormalizeCueEnds(cues, p(3000))
Expect(cues[0].End).To(BeNil())
Expect(cues[1].End).To(BeNil())
})
})