mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #7528 from lalyos/fix_version_number_comparison
Fix version number comparison
This commit is contained in:
commit
0771eb32dc
2 changed files with 12 additions and 5 deletions
|
@ -12,9 +12,17 @@ func (me Version) compareTo(other Version) int {
|
|||
meTab = strings.Split(string(me), ".")
|
||||
otherTab = strings.Split(string(other), ".")
|
||||
)
|
||||
for i, s := range meTab {
|
||||
|
||||
max := len(meTab)
|
||||
if len(otherTab) > max {
|
||||
max = len(otherTab)
|
||||
}
|
||||
for i := 0; i < max; i++ {
|
||||
var meInt, otherInt int
|
||||
meInt, _ = strconv.Atoi(s)
|
||||
|
||||
if len(meTab) > i {
|
||||
meInt, _ = strconv.Atoi(meTab[i])
|
||||
}
|
||||
if len(otherTab) > i {
|
||||
otherInt, _ = strconv.Atoi(otherTab[i])
|
||||
}
|
||||
|
@ -25,9 +33,6 @@ func (me Version) compareTo(other Version) int {
|
|||
return -1
|
||||
}
|
||||
}
|
||||
if len(otherTab) > len(meTab) {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ func assertVersion(t *testing.T, a, b string, result int) {
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue