Recognize spells from shared glossary documents
This commit is contained in:
@@ -279,7 +279,7 @@ func referenceSlots() []contracts.ReferenceSlot {
|
||||
return []contracts.ReferenceSlot{{
|
||||
Name: spellcatalog.SpellCatalogReferenceSlot,
|
||||
Description: "Optional canonical spell-name catalog used for normalization and duplicate identity.",
|
||||
AcceptedMediaTypes: []string{"application/json"},
|
||||
AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"},
|
||||
MaxBytes: 1048576,
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestModuleContractAndStrictOptions(t *testing.T) {
|
||||
ReferenceSlots: []contracts.ReferenceSlot{{
|
||||
Name: spellcatalog.SpellCatalogReferenceSlot,
|
||||
Description: "Optional canonical spell-name catalog used for normalization and duplicate identity.",
|
||||
AcceptedMediaTypes: []string{"application/json"},
|
||||
AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml"},
|
||||
MaxBytes: 1048576,
|
||||
}},
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
}
|
||||
if base.effectiveCatalog.BaseID() != spellcatalog.SRD5E2014ID || base.effectiveCatalog.Digest() == "" || len(base.effectiveCatalog.OverlayIDs()) != 0 {
|
||||
if base.effectiveCatalog.BaseID() != spellcatalog.SRD5E2014ID || base.effectiveCatalog.Digest() == "" || len(base.effectiveCatalog.CollectionNames()) != 0 {
|
||||
t.Fatalf("base catalog identity = %#v, want embedded catalog identity", base.effectiveCatalog)
|
||||
}
|
||||
if canonical, ok := base.effectiveCatalog.Lookup(" cure wounds "); !ok || canonical != "Cure Wounds" {
|
||||
@@ -73,8 +73,8 @@ func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("New(overlay) error = %v, want nil", err)
|
||||
}
|
||||
if got := overlay.effectiveCatalog.OverlayIDs(); !reflect.DeepEqual(got, []string{"campaign.example"}) {
|
||||
t.Fatalf("overlay IDs = %#v, want campaign.example", got)
|
||||
if got := overlay.effectiveCatalog.CollectionNames(); !reflect.DeepEqual(got, []string{"spells"}) {
|
||||
t.Fatalf("collection names = %#v, want spells", got)
|
||||
}
|
||||
if canonical, ok := overlay.effectiveCatalog.Lookup(" emberfall aegis "); !ok || canonical != "Aegis of Emberfall" {
|
||||
t.Fatalf("overlay alias lookup = %q, %t, want Aegis of Emberfall", canonical, ok)
|
||||
@@ -87,7 +87,7 @@ func TestNewRejectsInvalidCatalogReferencesDuringConstruction(t *testing.T) {
|
||||
Items: []contracts.ReferenceItem{{MediaType: "text/plain", Content: []byte("not a catalog")}},
|
||||
},
|
||||
}}
|
||||
if _, err := New(Options{}, invalid); err == nil || !strings.Contains(err.Error(), "application/json") {
|
||||
if _, err := New(Options{}, invalid); err == nil || !strings.Contains(err.Error(), "media type") {
|
||||
t.Fatalf("New(invalid reference) error = %v, want media type failure", err)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestNormalizeLimitsFindingsWithoutChangingSpellValues(t *testing.T) {
|
||||
|
||||
func TestNormalizeBoundsUnicodeNamesAndQuotesCanonicalReplacement(t *testing.T) {
|
||||
longName := strings.Repeat("火", 140)
|
||||
reference := spellCatalogReference(fmt.Sprintf(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v1","catalogs":[{"id":"campaign.long","ruleset":"dnd-5e-2014","source":{"title":"Private campaign source"},"spells":[{"name":%q,"aliases":["long alias"]}]}]}`, longName))
|
||||
reference := spellCatalogReference(fmt.Sprintf(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"long","name":%q,"category":"spell","aliases":["long alias"]}]}}}`, longName))
|
||||
normalizer, err := New(Options{}, reference)
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
@@ -503,7 +503,7 @@ func diagnosticByReason(diagnostics []contracts.ProducerDiagnostic, reason strin
|
||||
}
|
||||
|
||||
func overlayReference() contracts.ReferenceSet {
|
||||
return spellCatalogReference(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v1","catalogs":[{"id":"campaign.example","ruleset":"dnd-5e-2014","source":{"title":"Private campaign source","version":"1","url":"file:///private-source.json","license":"private"},"spells":[{"name":"Aegis of Emberfall","aliases":["Emberfall Aegis"]}]}]}`)
|
||||
return spellCatalogReference(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"aegis","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}]}}}`)
|
||||
}
|
||||
|
||||
func spellCatalogReference(content string) contracts.ReferenceSet {
|
||||
|
||||
Reference in New Issue
Block a user