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
diff --git a/.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 b/.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
new file mode 100644 (file)
index 0000000..3403660
--- /dev/null
@@ -0,0 +1,54 @@
+package a
+
+import "sort"
+
+// IncorrectSort tries to sort an integer.
+func IncorrectSort() {
+       i := 5
+       sortFn := func(i, j int) bool { return false }
+       sort.Slice(i, sortFn) // want "sort.Slice's argument must be a slice; is called with int"
+}
+
+// CorrectSort sorts integers. It should not produce a diagnostic.
+func CorrectSort() {
+       s := []int{2, 3, 5, 6}
+       sortFn := func(i, j int) bool { return s[i] < s[j] }
+       sort.Slice(s, sortFn)
+}
+
+// CorrectInterface sorts an interface with a slice
+// as the concrete type. It should not produce a diagnostic.
+func CorrectInterface() {
+       var s interface{}
+       s = interface{}([]int{2, 1, 0})
+       sortFn := func(i, j int) bool { return s.([]int)[i] < s.([]int)[j] }
+       sort.Slice(s, sortFn)
+}
+
+type slicecompare interface {
+       compare(i, j int) bool
+}
+
+type intslice []int
+
+func (s intslice) compare(i, j int) bool {
+       return s[i] < s[j]
+}
+
+// UnderlyingInterface sorts an interface with a slice
+// as the concrete type. It should not produce a diagnostic.
+func UnderlyingInterface() {
+       var s slicecompare
+       s = intslice([]int{2, 1, 0})
+       sort.Slice(s, s.compare)
+}
+
+type mySlice []int
+
+// UnderlyingSlice sorts a type with an underlying type of
+// slice of ints. It should not produce a diagnostic.
+func UnderlyingSlice() {
+       s := mySlice{2, 3, 5, 6}
+       sortFn := func(i, j int) bool { return s[i] < s[j] }
+       sort.Slice(s, sortFn)
+}