if err != nil {
panic(err)
}
- dirsInit(testdataDir)
+ dirsInit(testdataDir, filepath.Join(testdataDir, "nested"), filepath.Join(testdataDir, "nested", "nested"))
os.Exit(m.Run())
}
"\\)\n+const", // This will appear if the const decl appears twice.
},
},
+ {
+ "non-imported: pkg.sym",
+ []string{"nested.Foo"},
+ []string{"Foo struct"},
+ nil,
+ },
+ {
+ "non-imported: pkg only",
+ []string{"nested"},
+ []string{"Foo struct"},
+ nil,
+ },
+ {
+ "non-imported: pkg sym",
+ []string{"nested", "Foo"},
+ []string{"Foo struct"},
+ nil,
+ },
}
func TestDoc(t *testing.T) {
// Done below.
case 2:
// Package must be findable and importable.
- packagePath, ok := findPackage(arg)
- if !ok {
- return nil, args[0], args[1], false
+ for {
+ packagePath, ok := findNextPackage(arg)
+ if !ok {
+ break
+ }
+ if pkg, err := build.ImportDir(packagePath, build.ImportComment); err == nil {
+ return pkg, arg, args[1], true
+ }
}
- return importDir(packagePath), arg, args[1], true
+ return nil, args[0], args[1], false
}
// Usual case: one argument.
// If it contains slashes, it begins with a package path.
}
// See if we have the basename or tail of a package, as in json for encoding/json
// or ivy/value for robpike.io/ivy/value.
- path, ok := findPackage(arg[0:period])
- if ok {
- return importDir(path), arg[0:period], symbol, true
+ pkgName := arg[:period]
+ for {
+ path, ok := findNextPackage(pkgName)
+ if !ok {
+ break
+ }
+ if pkg, err = build.ImportDir(path, build.ImportComment); err == nil {
+ return pkg, arg[0:period], symbol, true
+ }
}
dirs.Reset() // Next iteration of for loop must scan all the directories again.
}
return unicode.IsUpper(ch)
}
-// findPackage returns the full file name path that first matches the
+// findNextPackage returns the next full file name path that matches the
// (perhaps partial) package path pkg. The boolean reports if any match was found.
-func findPackage(pkg string) (string, bool) {
+func findNextPackage(pkg string) (string, bool) {
if pkg == "" || isUpper(pkg) { // Upper case symbol cannot be a package name.
return "", false
}