Share edit location and check protected names in full segments
This commit is contained in:
@@ -30,9 +30,11 @@ func TestRecognizedTermsDeduplicateAndIncludePlurals(t *testing.T) {
|
||||
|
||||
func TestValidateProtectedTermsAppliesToNonGlossaryModule(t *testing.T) {
|
||||
req := Request{
|
||||
ModuleKey: "grammar",
|
||||
Glossary: []domain.Entry{{ID: "jesters", Name: "Jesters", Category: "faction"}},
|
||||
ProtectedTerms: domain.Vocabulary([]domain.Entry{{ID: "jesters", Name: "Jesters"}}, nil),
|
||||
WorkingTranscript: &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "Jesters"}}},
|
||||
ReplacementPolicy: proposals.ReplacementPolicyRequireUnique,
|
||||
ModuleKey: "grammar",
|
||||
Glossary: []domain.Entry{{ID: "jesters", Name: "Jesters", Category: "faction"}},
|
||||
ProtectedTerms: domain.Vocabulary([]domain.Entry{{ID: "jesters", Name: "Jesters"}}, nil),
|
||||
CandidateProposal: []proposals.EnrichedCorrectionProposal{
|
||||
{
|
||||
CorrectionProposal: proposals.CorrectionProposal{
|
||||
@@ -130,3 +132,32 @@ func TestProtectedNameFindingIdentifiesRemovedAlias(t *testing.T) {
|
||||
t.Fatalf("finding did not identify the removed alias: %+v", decision)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtectionRequiresAUsableFullSegmentPreview(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, source, span, replacement string
|
||||
target int
|
||||
rejected bool
|
||||
}{
|
||||
{"partial name change", "Cast Mage Armor.", "Mage", "Magus", 1, true},
|
||||
{"ambiguous span", "Mage Armor and Mage Armor", "Mage Armor", "ward", 1, false},
|
||||
{"missing span", "Jesters arrived", "Mage Armor", "ward", 1, false},
|
||||
{"missing target", "Mage Armor", "Mage Armor", "ward", 9, false},
|
||||
{"empty result", "Mage Armor", "Mage Armor", "", 1, true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := Request{
|
||||
ModuleKey: "grammar", ReplacementPolicy: proposals.ReplacementPolicyRequireUnique,
|
||||
ProtectedTerms: domain.Vocabulary([]domain.Entry{{ID: "mage", Name: "Mage Armor"}}, nil),
|
||||
WorkingTranscript: &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: tc.source}}},
|
||||
CandidateProposal: []proposals.EnrichedCorrectionProposal{{CorrectionProposal: proposals.CorrectionProposal{
|
||||
TargetSegmentID: tc.target, OriginalText: tc.span, CorrectedText: tc.replacement,
|
||||
}}},
|
||||
}
|
||||
result, err := ValidateProtectedTerms(req)
|
||||
if err != nil || len(result.Decisions) != 1 || result.Decisions[0].Approved == tc.rejected {
|
||||
t.Fatalf("protection decision = %+v (%v)", result, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user