Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prefix of any character #12

Merged
merged 10 commits into from
Nov 19, 2020
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
// The raw regular expression string used for testing the validity
// of a version.
const (
VersionRegexpRaw string = `[vV]?` + // Optional [vV] prefix
VersionRegexpRaw string = `(?:\w+\-)*[vV]?` + // Optional [vV] prefix
6543 marked this conversation as resolved.
Show resolved Hide resolved
`([0-9]+(\.[0-9]+)*?)` + // ( MajorNum ( '.' MinorNums ) *? )
`(-` + // Followed by (optionally): ( '-'
`([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)` + // Either ( PreNum String ( '.' OtherString ) * )
Expand Down
10 changes: 10 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestNewVersion(t *testing.T) {
{"1.2.beta", false},
{"1.21.beta", false},
{"v1.13.0-rc1", false},
{"controller-v0.40.2", false},
{"azure-cli-v1.4.2", false},

// Have Error
{"", true},
Expand Down Expand Up @@ -81,6 +83,8 @@ func TestNewSemver(t *testing.T) {
{"1.2.3.4-rc1-with-hypen", false},
{"1.2.3.4", false},
{"v1.2.3", false},
{"controller-v0.40.2", true},
{"azure-cli-v1.4.2", true},
{"1.2.beta", true},
{"1.21.beta", true},
{"foo1.2.3", true},
Expand Down Expand Up @@ -127,6 +131,12 @@ func TestVersionCompare(t *testing.T) {
{"2.29.0.rc0.261.g7178c9af9c", "2.29.0", -1},
{"2.29.0.rc0.261.g7178c9af9c", "2.29.0-rc1", -1},
{"1.2.0", "1.2.0-X-1.2.0+metadata~dist", 1},
{"controller-v0.40.2", "controller-v0.40.3", -1},
{"0.40.4", "controller-v0.40.2", 1},
{"0.40.4", "controller-v0.40.4", 0},
{"azure-cli-v1.4.2", "azure-cli-v1.4.2", 0},
{"azure-cli-v1.4.1", "azure-cli-v1.4.2", -1},
{"1.4.3", "azure-cli-v1.4.2", 1},
}

for _, tc := range cases {
Expand Down