Skip to content

Commit

Permalink
Fix a bug on sorting, which cause Pack don't work as expected (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wing924 authored Apr 18, 2023
1 parent 067bca3 commit 2670f48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.0.2 (2023-04-18)

* Fix a bug on sorting, which cause `Pack` don't work as expected

## 2.0.1 (2023-04-18)

* Fix slice access out of bound error
Expand Down
2 changes: 1 addition & 1 deletion v2/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (h *host) Less(rhs *host) bool {
}

m = min(len(h.Digits), len(rhs.Digits))
for i := 0; i < m; i++ {
for i := m - 1; i >= 0; i-- {
if h.Digits[i].Digit < rhs.Digits[i].Digit {
return true
}
Expand Down
21 changes: 21 additions & 0 deletions v2/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ func TestPack(t *testing.T) {
{[]string{"abc101z-02", "abc102z-02", "abc102z-03"}, []string{"abc[101-102]z-02", "abc102z-03"}},
{[]string{"abc101z-01", "abc102z-02", "abc102z-03"}, []string{"abc101z-01", "abc102z-[02-03]"}},
{[]string{"abc101z-01p", "abc101z-01q", "abc102z-01p", "abc102z-01q"}, []string{"abc[101-102]z-01p", "abc[101-102]z-01q"}},
{[]string{
"abc101z-01p",
"abc101z-01q",
"abc102z-01p",
"abc102z-01q",
"abc101z-02p",
"abc101z-02q",
"abc102z-02p",
"abc102z-02q",
"abc101z-03p",
"abc101z-04p",
"abc102z-03q",
"abc102z-04q",
}, []string{
"abc[101-102]z-01p",
"abc[101-102]z-02p",
"abc101z-[03-04]p",
"abc[101-102]z-01q",
"abc[101-102]z-02q",
"abc102z-[03-04]q",
}},
}
for _, test := range cases {
test := test
Expand Down

0 comments on commit 2670f48

Please sign in to comment.