blob: 9739d5a02e4fa4e79c15fd0882f4b46fc24b3889 [file] [log] [blame]
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package frontend
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"golang.org/x/pkgsite/internal"
)
func TestBreadcrumbPath(t *testing.T) {
for _, test := range []struct {
pkgPath, modPath, version string
want breadcrumb
}{
{
"example.com/blob/s3blob", "example.com", internal.LatestVersion,
breadcrumb{
Current: "s3blob",
Links: []link{
{"/example.com", "example.com"},
{"/example.com/blob", "blob"},
},
CopyData: "example.com/blob/s3blob",
},
},
{
"example.com", "example.com", internal.LatestVersion,
breadcrumb{
Current: "example.com",
Links: []link{},
CopyData: "example.com",
},
},
{
"g/x/tools/go/a", "g/x/tools", internal.LatestVersion,
breadcrumb{
Current: "a",
Links: []link{
{"/g/x/tools", "g/x/tools"},
{"/g/x/tools/go", "go"},
},
CopyData: "g/x/tools/go/a",
},
},
{
"golang.org/x/tools", "golang.org/x/tools", internal.LatestVersion,
breadcrumb{
Current: "golang.org/x/tools",
Links: []link{},
CopyData: "golang.org/x/tools",
},
},
{
// Special case: stdlib package.
"encoding/json", "std", internal.LatestVersion,
breadcrumb{
Current: "json",
Links: []link{{"/encoding", "encoding"}},
CopyData: "encoding/json",
},
},
{
// Special case: stdlib package.
"encoding/json", "std", "go1.15",
breadcrumb{
Current: "json",
Links: []link{{"/encoding@go1.15", "encoding"}},
CopyData: "encoding/json",
},
},
{
// Special case: stdlib module.
"std", "std", internal.LatestVersion,
breadcrumb{
Current: "Standard library",
Links: nil,
},
},
{
"example.com/blob/s3blob", "example.com", "v1",
breadcrumb{
Current: "s3blob",
Links: []link{
{"/example.com@v1", "example.com"},
{"/example.com/blob@v1", "blob"},
},
CopyData: "example.com/blob/s3blob",
},
},
} {
t.Run(fmt.Sprintf("%s-%s-%s", test.pkgPath, test.modPath, test.version), func(t *testing.T) {
got := breadcrumbPath(test.pkgPath, test.modPath, test.version)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("mismatch (-want, +got):\n%s", diff)
}
})
}
}