| ... | ... |
@@ -12,9 +12,17 @@ func (me Version) compareTo(other Version) int {
|
| 12 | 12 |
meTab = strings.Split(string(me), ".") |
| 13 | 13 |
otherTab = strings.Split(string(other), ".") |
| 14 | 14 |
) |
| 15 |
- for i, s := range meTab {
|
|
| 15 |
+ |
|
| 16 |
+ max := len(meTab) |
|
| 17 |
+ if len(otherTab) > max {
|
|
| 18 |
+ max = len(otherTab) |
|
| 19 |
+ } |
|
| 20 |
+ for i := 0; i < max; i++ {
|
|
| 16 | 21 |
var meInt, otherInt int |
| 17 |
- meInt, _ = strconv.Atoi(s) |
|
| 22 |
+ |
|
| 23 |
+ if len(meTab) > i {
|
|
| 24 |
+ meInt, _ = strconv.Atoi(meTab[i]) |
|
| 25 |
+ } |
|
| 18 | 26 |
if len(otherTab) > i {
|
| 19 | 27 |
otherInt, _ = strconv.Atoi(otherTab[i]) |
| 20 | 28 |
} |
| ... | ... |
@@ -25,9 +33,6 @@ func (me Version) compareTo(other Version) int {
|
| 25 | 25 |
return -1 |
| 26 | 26 |
} |
| 27 | 27 |
} |
| 28 |
- if len(otherTab) > len(meTab) {
|
|
| 29 |
- return -1 |
|
| 30 |
- } |
|
| 31 | 28 |
return 0 |
| 32 | 29 |
} |
| 33 | 30 |
|
| ... | ... |
@@ -12,6 +12,8 @@ func assertVersion(t *testing.T, a, b string, result int) {
|
| 12 | 12 |
|
| 13 | 13 |
func TestCompareVersion(t *testing.T) {
|
| 14 | 14 |
assertVersion(t, "1.12", "1.12", 0) |
| 15 |
+ assertVersion(t, "1.0.0", "1", 0) |
|
| 16 |
+ assertVersion(t, "1", "1.0.0", 0) |
|
| 15 | 17 |
assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) |
| 16 | 18 |
assertVersion(t, "1", "1.0.1", -1) |
| 17 | 19 |
assertVersion(t, "1.0.1", "1", 1) |