Reuse prepared glossary data across stage sections

This commit is contained in:
2026-11-10 20:42:28 +00:00
parent 8ad27e8368
commit c16d61e091
21 changed files with 174 additions and 142 deletions

View File

@@ -110,13 +110,14 @@ func TestExemptGlossarySpellingKeepsLongestMatchBoundary(t *testing.T) {
func TestValidationContextIncludesEachSharedDefinition(t *testing.T) {
entries := []glossary.Entry{
{Collection: "items", ID: "sword", Name: "Sword", Category: "item"},
{Collection: "spells", ID: "shield", Name: "Shield", Category: "spell"},
{Collection: "items", ID: "shield", Name: "Shield", Category: "item"},
{Collection: "items", ID: "sword", Name: "Sword", Category: "item"},
{Collection: "items", ID: "bow", Name: "Bow", Category: "item"},
}
segments := []schema.Segment{{ID: 1, Text: "Shield"}}
_, selected := validationContext(segments, 0, entries, NewProtectedVocabulary(glossary.Vocabulary(entries, nil)), "Barrier")
if len(selected) != 2 || selected[0].Category != "spell" || selected[1].ID != "shield" || selected[1].Collection != "items" {
segments := []schema.Segment{{ID: 1, Text: "Shield Shield"}}
_, selected := prepareGlossaryContext(entries).validationContext(segments, 0, "Sword")
if len(selected) != 3 || selected[0].ID != "sword" || selected[1].Category != "spell" || selected[2].ID != "shield" || selected[2].Collection != "items" {
t.Fatalf("selected=%+v", selected)
}
}