goose: add test that disambiguate contains the base name

No behavior change, just more unit testing.

Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Lewis <cflewis@google.com>
This commit is contained in:
Ross Light
2018-05-08 12:07:31 -04:00
parent 3c0eaf830e
commit cc91a772b0

View File

@@ -182,20 +182,24 @@ func TestUnexport(t *testing.T) {
func TestDisambiguate(t *testing.T) { func TestDisambiguate(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
contains string
collides map[string]bool collides map[string]bool
}{ }{
{"foo", nil}, {"foo", "foo", nil},
{"foo", map[string]bool{"foo": true}}, {"foo", "foo", map[string]bool{"foo": true}},
{"foo", map[string]bool{"foo": true, "foo1": true, "foo2": true}}, {"foo", "foo", map[string]bool{"foo": true, "foo1": true, "foo2": true}},
{"foo1", map[string]bool{"foo": true, "foo1": true, "foo2": true}}, {"foo1", "foo", map[string]bool{"foo": true, "foo1": true, "foo2": true}},
{"foo\u0661", map[string]bool{"foo": true, "foo1": true, "foo2": true}}, {"foo\u0661", "foo", map[string]bool{"foo": true, "foo1": true, "foo2": true}},
{"foo\u0661", map[string]bool{"foo": true, "foo1": true, "foo2": true, "foo\u0661": true}}, {"foo\u0661", "foo", map[string]bool{"foo": true, "foo1": true, "foo2": true, "foo\u0661": true}},
} }
for _, test := range tests { for _, test := range tests {
got := disambiguate(test.name, func(name string) bool { return test.collides[name] }) got := disambiguate(test.name, func(name string) bool { return test.collides[name] })
if !isIdent(got) { if !isIdent(got) {
t.Errorf("disambiguate(%q, %v) = %q; not an identifier", test.name, test.collides, got) t.Errorf("disambiguate(%q, %v) = %q; not an identifier", test.name, test.collides, got)
} }
if !strings.Contains(got, test.contains) {
t.Errorf("disambiguate(%q, %v) = %q; wanted to contain %q", test.name, test.collides, got, test.contains)
}
if test.collides[got] { if test.collides[got] {
t.Errorf("disambiguate(%q, %v) = %q; ", test.name, test.collides, got) t.Errorf("disambiguate(%q, %v) = %q; ", test.name, test.collides, got)
} }