Debian Codegraph @

go/analysis/passes/modernize/testdata/src/slicessort/slicessort.go.golden

raw
1 package slicessort
2
3 import "slices"
4
5 import "sort"
6
7 type myint int
8
9 func _(s []myint) {
10 slices.Sort(s) // want "sort.Slice can be modernized using slices.Sort"
11 }
12
13 func _(x *struct{ s []int }) {
14 slices.Sort(x.s) // want "sort.Slice can be modernized using slices.Sort"
15 }
16
17 func _(s []int) {
18 sort.Slice(s, func(i, j int) bool { return s[i] > s[j] }) // nope: wrong comparison operator
19 }
20
21 func _(s []int) {
22 sort.Slice(s, func(i, j int) bool { return s[j] < s[i] }) // nope: wrong index var
23 }
24
25 func _(sense bool, s2 []struct{ x int }) {
26 sort.Slice(s2, func(i, j int) bool { return s2[i].x < s2[j].x }) // nope: not a simple index operation
27
28 // Regression test for a crash: the sole statement of a
29 // comparison func body is not necessarily a return!
30 sort.Slice(s2, func(i, j int) bool {
31 if sense {
32 return s2[i].x < s2[j].x
33 } else {
34 return s2[i].x > s2[j].x
35 }
36 })
37 }