2021-03-05 03:27:12 +03:00
|
|
|
// Copyright 2021 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 internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCandidateModulePaths(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
in string
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{"", nil},
|
|
|
|
{".", nil},
|
|
|
|
{"///foo", nil},
|
|
|
|
{"github.com/google", nil},
|
|
|
|
{"std", []string{"std"}},
|
|
|
|
{"encoding/json", []string{"std"}},
|
|
|
|
{
|
|
|
|
"example.com/green/eggs/and/ham",
|
|
|
|
[]string{
|
|
|
|
"example.com/green/eggs/and/ham",
|
|
|
|
"example.com/green/eggs/and",
|
|
|
|
"example.com/green/eggs",
|
|
|
|
"example.com/green",
|
|
|
|
"example.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"github.com/google/go-cmp/cmp",
|
|
|
|
[]string{"github.com/google/go-cmp/cmp", "github.com/google/go-cmp"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bitbucket.org/ok/sure/no$dollars/allowed",
|
|
|
|
[]string{"bitbucket.org/ok/sure"},
|
|
|
|
},
|
2021-09-15 18:08:44 +03:00
|
|
|
{
|
|
|
|
// A module path cannot end in "v1".
|
|
|
|
"k8s.io/klog/v1",
|
|
|
|
[]string{"k8s.io/klog", "k8s.io"},
|
|
|
|
},
|
2021-03-05 03:27:12 +03:00
|
|
|
} {
|
|
|
|
got := CandidateModulePaths(test.in)
|
|
|
|
if !cmp.Equal(got, test.want) {
|
|
|
|
t.Errorf("%q: got %v, want %v", test.in, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|