opts gets the comparison opts for a type. This includes some defaults, but allows each type to explicitly append their own.
(a T)
| 52 | |
| 53 | // opts gets the comparison opts for a type. This includes some defaults, but allows each type to explicitly append their own. |
| 54 | func opts[T any](a T) []cmp.Option { |
| 55 | if o, ok := any(a).(cmpOptioner); ok { |
| 56 | opts := append([]cmp.Option{}, cmpOpts...) |
| 57 | opts = append(opts, o.CmpOpts()...) |
| 58 | return opts |
| 59 | } |
| 60 | // if T is actually a slice (ex: []A), check that and get the opts for the element type (A). |
| 61 | t := reflect.TypeOf(a) |
| 62 | if t != nil && t.Kind() == reflect.Slice { |
| 63 | v := reflect.New(t.Elem()).Elem().Interface() |
| 64 | if o, ok := v.(cmpOptioner); ok { |
| 65 | opts := append([]cmp.Option{}, cmpOpts...) |
| 66 | opts = append(opts, o.CmpOpts()...) |
| 67 | return opts |
| 68 | } |
| 69 | } |
| 70 | return cmpOpts |
| 71 | } |
| 72 | |
| 73 | var cmpOpts = []cmp.Option{protocmp.Transform(), cmpopts.EquateEmpty(), compareErrors} |
| 74 |
searching dependent graphs…