diff --git a/CHANGELOG.md b/CHANGELOG.md index bf06c4a..7425abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/v2/pack.go b/v2/pack.go index f0c190a..1f0dd7e 100644 --- a/v2/pack.go +++ b/v2/pack.go @@ -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 } diff --git a/v2/pack_test.go b/v2/pack_test.go index dc0f26a..0a80624 100644 --- a/v2/pack_test.go +++ b/v2/pack_test.go @@ -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