1 // Copyright 2017, The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE.md file.
10 pb "github.com/google/go-cmp/cmp/internal/testprotos"
13 // This is an sanitized example of equality from a real use-case.
14 // The original equality function was as follows:
16 func equalEagle(x, y Eagle) bool {
17 if x.Name != y.Name &&
18 !reflect.DeepEqual(x.Hounds, y.Hounds) &&
20 x.DescLong != y.DescLong &&
22 x.StateGoverner != y.StateGoverner &&
23 x.PrankRating != y.PrankRating &&
24 x.FunnyPrank != y.FunnyPrank &&
25 !pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {
29 if len(x.Dreamers) != len(y.Dreamers) {
32 for i := range x.Dreamers {
33 if !equalDreamer(x.Dreamers[i], y.Dreamers[i]) {
37 if len(x.Slaps) != len(y.Slaps) {
40 for i := range x.Slaps {
41 if !equalSlap(x.Slaps[i], y.Slaps[i]) {
47 func equalDreamer(x, y Dreamer) bool {
48 if x.Name != y.Name ||
50 x.DescLong != y.DescLong ||
51 x.ContSlapsInterval != y.ContSlapsInterval ||
52 x.Ornamental != y.Ornamental ||
53 x.Amoeba != y.Amoeba ||
54 x.Heroes != y.Heroes ||
55 x.FloppyDisk != y.FloppyDisk ||
56 x.MightiestDuck != y.MightiestDuck ||
57 x.FunnyPrank != y.FunnyPrank ||
58 !pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {
62 if len(x.Animal) != len(y.Animal) {
65 for i := range x.Animal {
68 if reflect.TypeOf(x.Animal) != reflect.TypeOf(y.Animal) {
73 if !equalGoat(vx.(Goat), vy.(Goat)) {
77 if !equalDonkey(vx.(Donkey), vy.(Donkey)) {
81 panic(fmt.Sprintf("unknown type: %T", vx))
84 if len(x.PreSlaps) != len(y.PreSlaps) {
87 for i := range x.PreSlaps {
88 if !equalSlap(x.PreSlaps[i], y.PreSlaps[i]) {
92 if len(x.ContSlaps) != len(y.ContSlaps) {
95 for i := range x.ContSlaps {
96 if !equalSlap(x.ContSlaps[i], y.ContSlaps[i]) {
102 func equalSlap(x, y Slap) bool {
103 return x.Name == y.Name &&
105 x.DescLong == y.DescLong &&
106 pb.Equal(x.Args, y.Args) &&
107 x.Tense == y.Tense &&
108 x.Interval == y.Interval &&
109 x.Homeland == y.Homeland &&
110 x.FunnyPrank == y.FunnyPrank &&
111 pb.Equal(x.Immutable.Proto(), y.Immutable.Proto())
113 func equalGoat(x, y Goat) bool {
114 if x.Target != y.Target ||
115 x.FunnyPrank != y.FunnyPrank ||
116 !pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {
119 if len(x.Slaps) != len(y.Slaps) {
122 for i := range x.Slaps {
123 if !equalSlap(x.Slaps[i], y.Slaps[i]) {
129 func equalDonkey(x, y Donkey) bool {
130 return x.Pause == y.Pause &&
131 x.Sleep == y.Sleep &&
132 x.FunnyPrank == y.FunnyPrank &&
133 pb.Equal(x.Immutable.Proto(), y.Immutable.Proto())
148 Immutable *EagleImmutable
151 type EagleImmutable struct {
153 State *pb.Eagle_States
154 MissingCall *pb.Eagle_MissingCalls
163 type Dreamer struct {
169 ContSlapsInterval int32
170 Animal []interface{} // Could be either Goat or Donkey
177 Immutable *DreamerImmutable
180 type DreamerImmutable struct {
182 State *pb.Dreamer_States
183 MissingCall *pb.Dreamer_MissingCalls
200 Immutable *SlapImmutable
203 type SlapImmutable struct {
208 State *pb.Slap_States
212 LoveRadius *LoveRadius
220 Immutable *GoatImmutable
223 type GoatImmutable struct {
225 State *pb.Goat_States
235 Immutable *DonkeyImmutable
238 type DonkeyImmutable struct {
240 State *pb.Donkey_States
247 type LoveRadius struct {
252 type SummerLove struct {
253 Summary *SummerLoveSummary
257 type SummerLoveSummary struct {
259 ChangeType []pb.SummerType
263 func (EagleImmutable) Proto() *pb.Eagle { return nil }
264 func (DreamerImmutable) Proto() *pb.Dreamer { return nil }
265 func (SlapImmutable) Proto() *pb.Slap { return nil }
266 func (GoatImmutable) Proto() *pb.Goat { return nil }
267 func (DonkeyImmutable) Proto() *pb.Donkey { return nil }