Refactor validators into built-in registry chains
This commit is contained in:
79
internal/validators/registry_test.go
Normal file
79
internal/validators/registry_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuiltInRegistryRegistersAllKeys(t *testing.T) {
|
||||
r := NewBuiltInRegistry()
|
||||
for _, key := range []string{
|
||||
KeyConfidenceThreshold,
|
||||
KeyOriginalTextPresence,
|
||||
KeyNonEmptyCorrectedText,
|
||||
KeyNoEffect,
|
||||
KeyProtectedTerms,
|
||||
KeySpokenFormPlausibility,
|
||||
KeyMeaningReversalReview,
|
||||
KeyEditorialReview,
|
||||
KeyGrammarReview,
|
||||
KeySpokenWordReview,
|
||||
} {
|
||||
def, ok := r.Lookup(key)
|
||||
if !ok {
|
||||
t.Fatalf("expected validator key %q to be registered", key)
|
||||
}
|
||||
v, err := def.Build()
|
||||
if err != nil {
|
||||
t.Fatalf("build validator %q: %v", key, err)
|
||||
}
|
||||
if v.Name() != key {
|
||||
t.Fatalf("expected validator name %q, got %q", key, v.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuiltInRegistryUnknownKeyFails(t *testing.T) {
|
||||
r := NewBuiltInRegistry()
|
||||
if _, err := r.MustBuild("missing"); err == nil {
|
||||
t.Fatalf("expected unknown validator key error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuiltInChainKeysResolveForProductionModules(t *testing.T) {
|
||||
for _, moduleKey := range []string{"glossary", "homophones", "spoken_word", "grammar"} {
|
||||
keys, err := BuiltInChainKeys(moduleKey)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve keys for %q: %v", moduleKey, err)
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
t.Fatalf("expected non-empty chain for %q", moduleKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveBuiltInChainUsesRegisteredKeys(t *testing.T) {
|
||||
r := NewBuiltInRegistry()
|
||||
for _, moduleKey := range []string{"glossary", "homophones", "spoken_word", "grammar"} {
|
||||
chain, err := ResolveBuiltInChain(moduleKey, r)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve chain for %q: %v", moduleKey, err)
|
||||
}
|
||||
if len(chain) == 0 {
|
||||
t.Fatalf("expected non-empty chain for %q", moduleKey)
|
||||
}
|
||||
for _, v := range chain {
|
||||
if v == nil {
|
||||
t.Fatalf("nil validator in %q chain", moduleKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuiltInChainUnknownModuleFails(t *testing.T) {
|
||||
if _, err := BuiltInChainKeys("unknown"); err == nil {
|
||||
t.Fatalf("expected unknown module chain failure")
|
||||
}
|
||||
if _, err := ResolveBuiltInChain("unknown", NewBuiltInRegistry()); err == nil {
|
||||
t.Fatalf("expected unknown module chain failure")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user