37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package glossary
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestVocabularyKeepsContributorsAndExemptsOnlyActiveSpellings(t *testing.T) {
|
|
plural := "Aegides"
|
|
active := []Entry{{Collection: "spells", ID: "shield", Name: "Shield", Aliases: []string{"Ward"}}}
|
|
protected := []Entry{
|
|
active[0],
|
|
{Collection: "items", ID: "shield", Name: "shield", Aliases: []string{"Aegis", "SHIELD"}, Plural: &plural},
|
|
active[0],
|
|
}
|
|
full := Vocabulary(protected, nil)
|
|
if !reflect.DeepEqual(full[0].Identities, []Identity{{Collection: "spells", ID: "shield"}, {Collection: "items", ID: "shield"}}) {
|
|
t.Fatalf("shared spelling contributors: %+v", full[0])
|
|
}
|
|
reduced := Vocabulary(protected, active)
|
|
var remaining, exempt []string
|
|
for _, term := range reduced {
|
|
if term.Exempt {
|
|
exempt = append(exempt, term.Spelling)
|
|
} else {
|
|
remaining = append(remaining, term.Spelling)
|
|
}
|
|
}
|
|
if !reflect.DeepEqual(remaining, []string{"Aegis", "Aegiss", "Aegides"}) ||
|
|
!reflect.DeepEqual(exempt, []string{"Shield", "Shields", "Ward", "Wards"}) {
|
|
t.Fatalf("protected: %v; exempt: %v", remaining, exempt)
|
|
}
|
|
if !reflect.DeepEqual(full, Vocabulary(protected, nil)) || protected[0].Aliases[0] != "Ward" {
|
|
t.Fatal("deriving an exemption changed another view or its inputs")
|
|
}
|
|
}
|