...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package testutil
16
17 import (
18 "math"
19 "math/big"
20
21 "github.com/google/go-cmp/cmp"
22 "google.golang.org/protobuf/proto"
23 )
24
25 var (
26 alwaysEqual = cmp.Comparer(func(_, _ interface{}) bool { return true })
27
28 defaultCmpOptions = []cmp.Option{
29
30 cmp.Comparer(proto.Equal),
31
32 cmp.Comparer(func(x, y *big.Rat) bool {
33 if x == nil || y == nil {
34 return x == y
35 }
36 return x.Cmp(y) == 0
37 }),
38
39 cmp.FilterValues(func(x, y float64) bool {
40 return math.IsNaN(x) && math.IsNaN(y)
41 }, alwaysEqual),
42 cmp.FilterValues(func(x, y float32) bool {
43 return math.IsNaN(float64(x)) && math.IsNaN(float64(y))
44 }, alwaysEqual),
45 }
46 )
47
48
49 func Equal(x, y interface{}, opts ...cmp.Option) bool {
50
51 opts = append(opts[:len(opts):len(opts)], defaultCmpOptions...)
52 return cmp.Equal(x, y, opts...)
53 }
54
55
56
57 func Diff(x, y interface{}, opts ...cmp.Option) string {
58
59 opts = append(opts[:len(opts):len(opts)], defaultCmpOptions...)
60 return cmp.Diff(x, y, opts...)
61 }
62
View as plain text