fix nil version comparisons, add equal func
This commit is contained in:
+12
-1
@@ -19,7 +19,11 @@ type Version struct {
|
||||
//
|
||||
// Extensions such as pre-release version or build metadata are ignored when comparing versions.
|
||||
func (a *Version) Compare(b *Version) int {
|
||||
if a == nil || b == nil {
|
||||
if a == nil && b != nil {
|
||||
return -1
|
||||
} else if a != nil && b == nil {
|
||||
return 1
|
||||
} else if a == nil && b == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -40,6 +44,13 @@ func (a *Version) Compare(b *Version) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// Equal checks for equality between two versions.
|
||||
//
|
||||
// Extensions such as pre-release version or build metadata are ignored when comparing versions.
|
||||
func (a *Version) Equal(b *Version) bool {
|
||||
return a.Compare(b) == 0
|
||||
}
|
||||
|
||||
// Match tests the version against a constraint.
|
||||
// Gt and Lt take precedence over Gte and Lte.
|
||||
func (v *Version) Match(c *Constraint) bool {
|
||||
|
||||
Reference in New Issue
Block a user