Skip to content

Commit

Permalink
chore: make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 12, 2024
1 parent a3cc6dd commit c41869f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions matcher_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zero

import (
"slices"
"cmp"

Check failure on line 4 in matcher_test.go

View workflow job for this annotation

GitHub Actions / CI

package cmp is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/cmp)
"strconv"
"testing"
)
Expand Down Expand Up @@ -38,10 +38,26 @@ func Test_sortMatcher(t *testing.T) {
for i := 0; i < block*batch; i += block {
batchRes := result[i : i+block]
// 优先级从1开始的matcher先注册后执行,所以结果是逆序的
slices.Reverse(batchRes)
if !slices.IsSorted(batchRes) {
reverse(batchRes)
if !isSorted(batchRes) {
t.Fatalf("matcherList is not sorted, sort func is not stable: %v", batchRes)
}
}
}

// reverse reverses the elements of the slice in place.
func reverse[S ~[]E, E any](s S) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}

// isSorted reports whether x is sorted in ascending order.
func isSorted[S ~[]E, E cmp.Ordered](x S) bool {
for i := len(x) - 1; i > 0; i-- {
if cmp.Less(x[i], x[i-1]) {
return false
}
}
return true
}

0 comments on commit c41869f

Please sign in to comment.