Skip to content

Commit 6ae0217

Browse files
authored
Merge pull request #20 from bugst/fix_extreme_compares
Fix extreme compare cases with "relaxed" versions
2 parents b4bf3c6 + 8328806 commit 6ae0217

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.github/workflows/test.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: Run unit tests with coverage
3838
run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
3939
shell: bash
40-
- uses: codecov/codecov-action@v2
40+
- uses: codecov/codecov-action@v5
4141
with:
4242
verbose: true
43+
env:
44+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
45+

version.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ func (v *Version) CompareTo(u *Version) int {
133133
return -1
134134
}
135135
} else if vMajor == 0 && u.bytes[uIdx] == '0' {
136-
return 0
136+
// continue
137137
} else if uMajor == 0 && v.bytes[vIdx] == '0' {
138-
return 0
138+
// continue
139139
} else if vMajor > uMajor {
140140
return 1
141141
} else {
@@ -162,9 +162,9 @@ func (v *Version) CompareTo(u *Version) int {
162162
return -1
163163
}
164164
} else if vMinor == vMajor && u.bytes[uIdx] == '0' {
165-
return 0
165+
// continue
166166
} else if uMinor == uMajor && v.bytes[vIdx] == '0' {
167-
return 0
167+
// continue
168168
} else if la > lb {
169169
return 1
170170
} else {

version_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,19 @@ func TestVersionComparator(t *testing.T) {
8080
}
8181
}
8282
}
83+
ascending(t, false, "", "0.0.1")
84+
ascending(t, false, "", "0.1")
85+
ascending(t, false, "", "1")
86+
ascending(t, false, "0", "0.0.1")
87+
ascending(t, false, "0", "0.1")
88+
ascending(t, false, "0", "1")
89+
ascending(t, false, "0.0", "0.0.1")
90+
ascending(t, false, "0.0", "0.1")
91+
ascending(t, false, "0.0", "1")
8392
ascending(t, false,
93+
"",
94+
"0.0.1",
95+
"0.1",
8496
"1.0.0-2",
8597
"1.0.0-11",
8698
"1.0.0-11a",

0 commit comments

Comments
 (0)