Restore fast typed decoding for ordinary transcripts

This commit is contained in:
2026-11-17 12:57:47 +00:00
parent 19755e1d47
commit 3e107bedd1
4 changed files with 176 additions and 36 deletions

View File

@@ -366,6 +366,34 @@ func TestSourceTranscriptUsesEffectiveMemberValues(t *testing.T) {
}
}
func TestSourceTranscriptCombinesOrdinaryAndAliasedMembers(t *testing.T) {
id := "7"
if strconv.IntSize == 64 {
id = "9007199254740993"
}
wantID, _ := strconv.Atoi(id)
segments := `[
{"speaker":"A","text":"He said \"{hello, world}\".","id":SOURCE_ID,
"extra":{"speaker":12,"TEXT":"metadata"}},
{"speaker":17,"spea\u006ber":"B","text":"expected","TEXT":"other","categories":[]},
{"speaker":"C","ſpeaker":"D","text":"last"}
]`
segments = strings.Replace(segments, "SOURCE_ID", id, 1)
for _, raw := range []string{segments, `{"segments":` + segments + "}"} {
transcript, err := ParseSourceTranscriptJSON([]byte(raw))
if err != nil {
t.Fatal(err)
}
got := transcript.Canonical().Segments
if len(got) != 3 || got[0].Speaker != "A" || got[0].ID != wantID ||
got[0].Text != `He said "{hello, world}".` ||
got[1].Speaker != "B" || got[1].Text != "expected" || got[1].Categories == nil ||
got[2].Speaker != "D" || got[2].Text != "last" {
t.Fatalf("unexpected segments: %+v", got)
}
}
}
func TestTranscriptClonePreservesPresenceAndIndependence(t *testing.T) {
original := &Transcript{Segments: []Segment{
{ID: 40, Text: "original", Categories: []string{"keep"}},