relax validity tests to break on slash
Change-Id: I1578a0aa77ee1fc957bb9a93690ed92633d3a65a
This commit is contained in:
parent
295a7c3840
commit
227eb4a551
16
vain.go
16
vain.go
@ -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.
|
||||
func Valid(p string, packages []Package) bool {
|
||||
ps := strings.Split(p, "/")
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,13 @@ func TestValid(t *testing.T) {
|
||||
in: "foo/bar/baz",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
pkgs: []Package{
|
||||
{Path: "a/b"},
|
||||
},
|
||||
in: "a/bb",
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
got := Valid(test.in, test.pkgs)
|
||||
|
Loading…
Reference in New Issue
Block a user