Remove pkg/version
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
a13b457fb4
commit
0468629ae5
2 changed files with 0 additions and 95 deletions
|
@ -1,68 +0,0 @@
|
||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Version provides utility methods for comparing versions.
|
|
||||||
type Version string
|
|
||||||
|
|
||||||
func (v Version) compareTo(other Version) int {
|
|
||||||
var (
|
|
||||||
currTab = strings.Split(string(v), ".")
|
|
||||||
otherTab = strings.Split(string(other), ".")
|
|
||||||
)
|
|
||||||
|
|
||||||
max := len(currTab)
|
|
||||||
if len(otherTab) > max {
|
|
||||||
max = len(otherTab)
|
|
||||||
}
|
|
||||||
for i := 0; i < max; i++ {
|
|
||||||
var currInt, otherInt int
|
|
||||||
|
|
||||||
if len(currTab) > i {
|
|
||||||
currInt, _ = strconv.Atoi(currTab[i])
|
|
||||||
}
|
|
||||||
if len(otherTab) > i {
|
|
||||||
otherInt, _ = strconv.Atoi(otherTab[i])
|
|
||||||
}
|
|
||||||
if currInt > otherInt {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if otherInt > currInt {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the version string
|
|
||||||
func (v Version) String() string {
|
|
||||||
return string(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LessThan checks if a version is less than another
|
|
||||||
func (v Version) LessThan(other Version) bool {
|
|
||||||
return v.compareTo(other) == -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// LessThanOrEqualTo checks if a version is less than or equal to another
|
|
||||||
func (v Version) LessThanOrEqualTo(other Version) bool {
|
|
||||||
return v.compareTo(other) <= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// GreaterThan checks if a version is greater than another
|
|
||||||
func (v Version) GreaterThan(other Version) bool {
|
|
||||||
return v.compareTo(other) == 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// GreaterThanOrEqualTo checks if a version is greater than or equal to another
|
|
||||||
func (v Version) GreaterThanOrEqualTo(other Version) bool {
|
|
||||||
return v.compareTo(other) >= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equal checks if a version is equal to another
|
|
||||||
func (v Version) Equal(other Version) bool {
|
|
||||||
return v.compareTo(other) == 0
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func assertVersion(t *testing.T, a, b string, result int) {
|
|
||||||
if r := Version(a).compareTo(Version(b)); r != result {
|
|
||||||
t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCompareVersion(t *testing.T) {
|
|
||||||
assertVersion(t, "1.12", "1.12", 0)
|
|
||||||
assertVersion(t, "1.0.0", "1", 0)
|
|
||||||
assertVersion(t, "1", "1.0.0", 0)
|
|
||||||
assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1)
|
|
||||||
assertVersion(t, "1", "1.0.1", -1)
|
|
||||||
assertVersion(t, "1.0.1", "1", 1)
|
|
||||||
assertVersion(t, "1.0.1", "1.0.2", -1)
|
|
||||||
assertVersion(t, "1.0.2", "1.0.3", -1)
|
|
||||||
assertVersion(t, "1.0.3", "1.1", -1)
|
|
||||||
assertVersion(t, "1.1", "1.1.1", -1)
|
|
||||||
assertVersion(t, "1.1.1", "1.1.2", -1)
|
|
||||||
assertVersion(t, "1.1.2", "1.2", -1)
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue