Share edit location and check protected names in full segments

This commit is contained in:
2026-11-16 04:09:25 +00:00
parent 43ce620122
commit 475557e4de
23 changed files with 488 additions and 269 deletions

View File

@@ -170,6 +170,35 @@ func TestApplyProposalsRequireUniqueAmbiguousSkip(t *testing.T) {
}
}
func TestPreviewAndApplyHandleOverlappingOccurrences(t *testing.T) {
transcript := &schema.Transcript{Segments: []schema.Segment{{ID: 71, Text: "banana"}}}
edit := EnrichedCorrectionProposal{CorrectionProposal: CorrectionProposal{
TargetSegmentID: 71, OriginalText: "ana", CorrectedText: "X",
}}
for _, tc := range []struct {
policy ReplacementPolicy
text string
skip ProposalSkipReason
}{
{ReplacementPolicyRequireUnique, "banana", SkipReasonAmbiguousOriginal},
{ReplacementPolicyReplaceAll, "bXna", ""},
} {
preview := PreviewProposalForSegment(&transcript.Segments[0], edit.CorrectionProposal, tc.policy)
result := ApplyProposals(transcript, []EnrichedCorrectionProposal{edit}, tc.policy, nil)
if result.Transcript.Segments[0].Text != tc.text {
t.Fatalf("%s produced %q", tc.policy, result.Transcript.Segments[0].Text)
}
if tc.skip != "" {
if preview.HasResult() || preview.SkipReason != tc.skip || len(result.Skipped) != 1 || result.Skipped[0].SkipReason != tc.skip {
t.Fatalf("%s preview %+v and apply %+v disagree with expected skip", tc.policy, preview, result)
}
} else if !preview.Applicable || preview.CorrectedSegmentText != tc.text ||
len(result.Applied) != 1 || result.Applied[0].ReplacementCount != 1 {
t.Fatalf("%s preview %+v and apply %+v disagree with expected edit", tc.policy, preview, result)
}
}
}
func TestApplyProposalsReplaceAllMultipleReplacements(t *testing.T) {
transcript := &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "uh uh uh"}}}
proposals := []EnrichedCorrectionProposal{