Reuse alias tree for discovery and help
This commit is contained in:
@@ -314,3 +314,34 @@ func (machine *Machine) classify(token string) symbol {
|
||||
}
|
||||
return symbol{kind: otherSymbol}
|
||||
}
|
||||
|
||||
func TestResolverSourcePrefixesAndDescendantsAreOwned(t *testing.T) {
|
||||
resolver, err := NewResolver([]Mapping{
|
||||
{Source: commandpath.Path{"a"}, Target: commandpath.Path{"root"}},
|
||||
{Source: commandpath.Path{"a", "b", "one"}, Target: commandpath.Path{"root", "one"}},
|
||||
{Source: commandpath.Path{"a", "b", "two"}, Target: commandpath.Path{"root", "two"}},
|
||||
{Source: commandpath.Path{"other"}, Target: commandpath.Path{"root"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prefixes := resolver.ProperSourcePrefixes()
|
||||
if len(prefixes) != 2 || !prefixes[0].Equal(commandpath.Path{"a"}) || !prefixes[1].Equal(commandpath.Path{"a", "b"}) {
|
||||
t.Fatalf("prefixes = %#v", prefixes)
|
||||
}
|
||||
prefixes[0][0] = "mutated"
|
||||
descendants := resolver.Descendants(commandpath.Path{"a"})
|
||||
if len(descendants) != 2 {
|
||||
t.Fatalf("descendants = %#v", descendants)
|
||||
}
|
||||
for _, mapping := range descendants {
|
||||
if len(mapping.Source) != 3 || mapping.Source[0] != "a" {
|
||||
t.Fatalf("mapping = %#v", mapping)
|
||||
}
|
||||
}
|
||||
descendants[0].Source[0] = "mutated"
|
||||
descendants[0].Target[0] = "mutated"
|
||||
if !resolver.Resolve(commandpath.Path{"a", "b", "one"}).Equal(commandpath.Path{"root", "one"}) || len(resolver.Descendants(commandpath.Path{"missing"})) != 0 {
|
||||
t.Fatal("resolver was mutated or missing branch returned mappings")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user