MCPcopy
hub / github.com/google/go-cmp / TestSortKeys

Function TestSortKeys

cmp/internal/value/sort_test.go:16–159  ·  cmp/internal/value/sort_test.go::TestSortKeys
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestSortKeys(t *testing.T) {
17 type (
18 MyString string
19 MyArray [2]int
20 MyStruct struct {
21 A MyString
22 B MyArray
23 C chan float64
24 }
25 EmptyStruct struct{}
26 )
27
28 opts := []cmp.Option{
29 cmp.Comparer(func(x, y float64) bool {
30 if math.IsNaN(x) && math.IsNaN(y) {
31 return true
32 }
33 return x == y
34 }),
35 cmp.Comparer(func(x, y complex128) bool {
36 rx, ix, ry, iy := real(x), imag(x), real(y), imag(y)
37 if math.IsNaN(rx) && math.IsNaN(ry) {
38 rx, ry = 0, 0
39 }
40 if math.IsNaN(ix) && math.IsNaN(iy) {
41 ix, iy = 0, 0
42 }
43 return rx == ry && ix == iy
44 }),
45 cmp.Comparer(func(x, y chan bool) bool { return true }),
46 cmp.Comparer(func(x, y chan int) bool { return true }),
47 cmp.Comparer(func(x, y chan float64) bool { return true }),
48 cmp.Comparer(func(x, y chan interface{}) bool { return true }),
49 cmp.Comparer(func(x, y *int) bool { return true }),
50 }
51
52 tests := []struct {
53 in map[interface{}]bool // Set of keys to sort
54 want []interface{}
55 }{{
56 in: map[interface{}]bool{1: true, 2: true, 3: true},
57 want: []interface{}{1, 2, 3},
58 }, {
59 in: map[interface{}]bool{
60 nil: true,
61 true: true,
62 false: true,
63 -5: true,
64 -55: true,
65 -555: true,
66 uint(1): true,
67 uint(11): true,
68 uint(111): true,
69 "abc": true,
70 "abcd": true,
71 "abcde": true,
72 "foo": true,
73 "bar": true,

Callers

nothing calls this directly

Calls 6

ComparerFunction · 0.92
SortKeysFunction · 0.92
DiffFunction · 0.92
MyArrayTypeAlias · 0.85
MyStringTypeAlias · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected