Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / go / analysis / passes / sortslice / testdata / src / a / a.go
1 package a
2
3 import "sort"
4
5 // IncorrectSort tries to sort an integer.
6 func IncorrectSort() {
7         i := 5
8         sortFn := func(i, j int) bool { return false }
9         sort.Slice(i, sortFn) // want "sort.Slice's argument must be a slice; is called with int"
10 }
11
12 // CorrectSort sorts integers. It should not produce a diagnostic.
13 func CorrectSort() {
14         s := []int{2, 3, 5, 6}
15         sortFn := func(i, j int) bool { return s[i] < s[j] }
16         sort.Slice(s, sortFn)
17 }
18
19 // CorrectInterface sorts an interface with a slice
20 // as the concrete type. It should not produce a diagnostic.
21 func CorrectInterface() {
22         var s interface{}
23         s = interface{}([]int{2, 1, 0})
24         sortFn := func(i, j int) bool { return s.([]int)[i] < s.([]int)[j] }
25         sort.Slice(s, sortFn)
26 }
27
28 type slicecompare interface {
29         compare(i, j int) bool
30 }
31
32 type intslice []int
33
34 func (s intslice) compare(i, j int) bool {
35         return s[i] < s[j]
36 }
37
38 // UnderlyingInterface sorts an interface with a slice
39 // as the concrete type. It should not produce a diagnostic.
40 func UnderlyingInterface() {
41         var s slicecompare
42         s = intslice([]int{2, 1, 0})
43         sort.Slice(s, s.compare)
44 }
45
46 type mySlice []int
47
48 // UnderlyingSlice sorts a type with an underlying type of
49 // slice of ints. It should not produce a diagnostic.
50 func UnderlyingSlice() {
51         s := mySlice{2, 3, 5, 6}
52         sortFn := func(i, j int) bool { return s[i] < s[j] }
53         sort.Slice(s, sortFn)
54 }