module: add unit test for MatchPathMajor, CheckPathMajor

Requested in CL 201497. The corresponding change will be made there
after this is merged.

Change-Id: I0726c475a34a5959e5b43f126e6bf03815686385
Reviewed-on: https://go-review.googlesource.com/c/mod/+/201517
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/module/module.go b/module/module.go
index abd8149..21f1239 100644
--- a/module/module.go
+++ b/module/module.go
@@ -511,6 +511,9 @@
 // CheckPathMajor returns a non-nil error if the semantic version v
 // does not match the path major version pathMajor.
 func CheckPathMajor(v, pathMajor string) error {
+	// TODO(jayconrod): return errors or panic for invalid inputs. This function
+	// (and others) was covered by integration tests for cmd/go, and surrounding
+	// code protected against invalid inputs like non-canonical versions.
 	if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
 		pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
 	}
diff --git a/module/module_test.go b/module/module_test.go
index 87f8ec8..bdf38c3 100644
--- a/module/module_test.go
+++ b/module/module_test.go
@@ -317,3 +317,26 @@
 		}
 	}
 }
+
+func TestMatchPathMajor(t *testing.T) {
+	for _, test := range []struct {
+		v, pathMajor string
+		want         bool
+	}{
+		{"v0.0.0", "", true},
+		{"v0.0.0", "/v2", false},
+		{"v0.0.0", ".v0", true},
+		{"v0.0.0-20190510104115-cbcb75029529", ".v1", true},
+		{"v1.0.0", "/v2", false},
+		{"v1.0.0", ".v1", true},
+		{"v1.0.0", ".v1-unstable", true},
+		{"v2.0.0+incompatible", "", true},
+		{"v2.0.0", "", false},
+		{"v2.0.0", "/v2", true},
+		{"v2.0.0", ".v2", true},
+	} {
+		if got := MatchPathMajor(test.v, test.pathMajor); got != test.want {
+			t.Errorf("MatchPathMajor(%q, %q) = %v, want %v", test.v, test.pathMajor, got, test.want)
+		}
+	}
+}