godoc: index import counts, package name to path(s), and exported symbols
R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/22190047
diff --git a/godoc/index_test.go b/godoc/index_test.go
index 001d2a7..8a5a473 100644
--- a/godoc/index_test.go
+++ b/godoc/index_test.go
@@ -17,6 +17,8 @@
"src/pkg/foo/foo.go": `// Package foo is an example.
package foo
+import "bar"
+
// Foo is stuff.
type Foo struct{}
@@ -27,6 +29,10 @@
"src/pkg/bar/bar.go": `// Package bar is another example to test races.
package bar
`,
+ "src/pkg/other/bar/bar.go": `// Package bar is another bar package.
+package bar
+func X() {}
+`,
"src/pkg/skip/skip.go": `// Package skip should be skipped.
package skip
func Skip() {}
@@ -46,11 +52,43 @@
t.Fatal("no index")
}
t.Logf("Got: %#v", ix)
- wantStats := Statistics{Bytes: 179, Files: 2, Lines: 11, Words: 5, Spots: 7}
+
+ wantStats := Statistics{Bytes: 256, Files: 3, Lines: 16, Words: 6, Spots: 9}
if !reflect.DeepEqual(ix.Stats(), wantStats) {
t.Errorf("Stats = %#v; want %#v", ix.Stats(), wantStats)
}
+
if _, ok := ix.words["Skip"]; ok {
t.Errorf("the word Skip was found; expected it to be skipped")
}
+
+ if got, want := ix.ImportCount(), map[string]int{
+ "bar": 1,
+ }; !reflect.DeepEqual(got, want) {
+ t.Errorf("ImportCount = %v; want %v", got, want)
+ }
+
+ if got, want := ix.PackagePath(), map[string]map[string]bool{
+ "foo": map[string]bool{
+ "foo": true,
+ },
+ "bar": map[string]bool{
+ "bar": true,
+ "other/bar": true,
+ },
+ }; !reflect.DeepEqual(got, want) {
+ t.Errorf("PackagePath = %v; want %v", got, want)
+ }
+
+ if got, want := ix.Exports(), map[string]map[string]SpotKind{
+ "foo": map[string]SpotKind{
+ "Foo": TypeDecl,
+ "New": FuncDecl,
+ },
+ "other/bar": map[string]SpotKind{
+ "X": FuncDecl,
+ },
+ }; !reflect.DeepEqual(got, want) {
+ t.Errorf("Exports = %v; want %v", got, want)
+ }
}