relax validity tests to break on slash

Change-Id: I1578a0aa77ee1fc957bb9a93690ed92633d3a65a
This commit is contained in:
Stephen McQuay 2016-06-03 17:37:05 -07:00
parent 295a7c3840
commit 227eb4a551
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D
2 changed files with 22 additions and 1 deletions

16
vain.go
View File

@ -50,10 +50,24 @@ func (p Package) String() string {
) )
} }
func splitPathHasPrefix(path, prefix []string) bool {
if len(path) < len(prefix) {
return false
}
for i, p := range prefix {
if path[i] != p {
return false
}
}
return true
}
// Valid checks that p will not confuse the go tool if added to packages. // Valid checks that p will not confuse the go tool if added to packages.
func Valid(p string, packages []Package) bool { func Valid(p string, packages []Package) bool {
ps := strings.Split(p, "/")
for _, pkg := range packages { for _, pkg := range packages {
if strings.HasPrefix(pkg.Path, p) || strings.HasPrefix(p, pkg.Path) { pre := strings.Split(pkg.Path, "/")
if splitPathHasPrefix(ps, pre) || splitPathHasPrefix(pre, ps) {
return false return false
} }
} }

View File

@ -113,6 +113,13 @@ func TestValid(t *testing.T) {
in: "foo/bar/baz", in: "foo/bar/baz",
want: true, want: true,
}, },
{
pkgs: []Package{
{Path: "a/b"},
},
in: "a/bb",
want: true,
},
} }
for _, test := range tests { for _, test := range tests {
got := Valid(test.in, test.pkgs) got := Valid(test.in, test.pkgs)