We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 69ba298 commit 85dfc4dCopy full SHA for 85dfc4d
module/module.go
@@ -511,6 +511,9 @@ func MatchPathMajor(v, pathMajor string) bool {
511
// CheckPathMajor returns a non-nil error if the semantic version v
512
// does not match the path major version pathMajor.
513
func CheckPathMajor(v, pathMajor string) error {
514
+ // TODO(jayconrod): return errors or panic for invalid inputs. This function
515
+ // (and others) was covered by integration tests for cmd/go, and surrounding
516
+ // code protected against invalid inputs like non-canonical versions.
517
if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
518
pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
519
}
module/module_test.go
@@ -317,3 +317,26 @@ func TestUnescapePath(t *testing.T) {
317
318
319
320
+
321
+func TestMatchPathMajor(t *testing.T) {
322
+ for _, test := range []struct {
323
+ v, pathMajor string
324
+ want bool
325
+ }{
326
+ {"v0.0.0", "", true},
327
+ {"v0.0.0", "/v2", false},
328
+ {"v0.0.0", ".v0", true},
329
+ {"v0.0.0-20190510104115-cbcb75029529", ".v1", true},
330
+ {"v1.0.0", "/v2", false},
331
+ {"v1.0.0", ".v1", true},
332
+ {"v1.0.0", ".v1-unstable", true},
333
+ {"v2.0.0+incompatible", "", true},
334
+ {"v2.0.0", "", false},
335
+ {"v2.0.0", "/v2", true},
336
+ {"v2.0.0", ".v2", true},
337
+ } {
338
+ if got := MatchPathMajor(test.v, test.pathMajor); got != test.want {
339
+ t.Errorf("MatchPathMajor(%q, %q) = %v, want %v", test.v, test.pathMajor, got, test.want)
340
+ }
341
342
+}
0 commit comments