Skip to content

Commit 9f49ee5

Browse files
committed
Use slices.Sort insted of sort.Slice
1 parent e48613b commit 9f49ee5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

internal/json/patch_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package json_test
55

66
import (
7-
"sort"
7+
"slices"
88
"testing"
99

1010
"github.com/google/go-cmp/cmp"
@@ -80,11 +80,20 @@ func TestCreatePatchFromStrings(t *testing.T) {
8080
sortTransformer := cmp.Transformer("SortPatchOps", func(ops []mattbairdjsonpatch.JsonPatchOperation) []mattbairdjsonpatch.JsonPatchOperation {
8181
sorted := make([]mattbairdjsonpatch.JsonPatchOperation, len(ops))
8282
copy(sorted, ops)
83-
sort.Slice(sorted, func(i, j int) bool {
84-
if sorted[i].Operation != sorted[j].Operation {
85-
return sorted[i].Operation < sorted[j].Operation
83+
slices.SortFunc(sorted, func(a, b mattbairdjsonpatch.JsonPatchOperation) int {
84+
if a.Operation != b.Operation {
85+
if a.Operation < b.Operation {
86+
return -1
87+
}
88+
return 1
8689
}
87-
return sorted[i].Path < sorted[j].Path
90+
if a.Path < b.Path {
91+
return -1
92+
}
93+
if a.Path > b.Path {
94+
return 1
95+
}
96+
return 0
8897
})
8998
return sorted
9099
})

0 commit comments

Comments
 (0)