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. 4 5package teststructs 6 7type InterfaceA interface { 8 InterfaceA() 9} 10 11type ( 12 StructA struct{ X string } // Equal method on value receiver 13 StructB struct{ X string } // Equal method on pointer receiver 14 StructC struct{ X string } // Equal method (with interface argument) on value receiver 15 StructD struct{ X string } // Equal method (with interface argument) on pointer receiver 16 StructE struct{ X string } // Equal method (with interface argument on value receiver) on pointer receiver 17 StructF struct{ X string } // Equal method (with interface argument on pointer receiver) on value receiver 18 19 // These embed the above types as a value. 20 StructA1 struct { 21 StructA 22 X string 23 } 24 StructB1 struct { 25 StructB 26 X string 27 } 28 StructC1 struct { 29 StructC 30 X string 31 } 32 StructD1 struct { 33 StructD 34 X string 35 } 36 StructE1 struct { 37 StructE 38 X string 39 } 40 StructF1 struct { 41 StructF 42 X string 43 } 44 45 // These embed the above types as a pointer. 46 StructA2 struct { 47 *StructA 48 X string 49 } 50 StructB2 struct { 51 *StructB 52 X string 53 } 54 StructC2 struct { 55 *StructC 56 X string 57 } 58 StructD2 struct { 59 *StructD 60 X string 61 } 62 StructE2 struct { 63 *StructE 64 X string 65 } 66 StructF2 struct { 67 *StructF 68 X string 69 } 70 71 StructNo struct{ X string } // Equal method (with interface argument) on non-satisfying receiver 72 73 AssignA func() int 74 AssignB struct{ A int } 75 AssignC chan bool 76 AssignD <-chan bool 77) 78 79func (x StructA) Equal(y StructA) bool { return true } 80func (x *StructB) Equal(y *StructB) bool { return true } 81func (x StructC) Equal(y InterfaceA) bool { return true } 82func (x StructC) InterfaceA() {} 83func (x *StructD) Equal(y InterfaceA) bool { return true } 84func (x *StructD) InterfaceA() {} 85func (x *StructE) Equal(y InterfaceA) bool { return true } 86func (x StructE) InterfaceA() {} 87func (x StructF) Equal(y InterfaceA) bool { return true } 88func (x *StructF) InterfaceA() {} 89func (x StructNo) Equal(y InterfaceA) bool { return true } 90 91func (x AssignA) Equal(y func() int) bool { return true } 92func (x AssignB) Equal(y struct{ A int }) bool { return true } 93func (x AssignC) Equal(y chan bool) bool { return true } 94func (x AssignD) Equal(y <-chan bool) bool { return true } 95 96var _ = func( 97 a StructA, b StructB, c StructC, d StructD, e StructE, f StructF, 98 ap *StructA, bp *StructB, cp *StructC, dp *StructD, ep *StructE, fp *StructF, 99 a1 StructA1, b1 StructB1, c1 StructC1, d1 StructD1, e1 StructE1, f1 StructF1, 100 a2 StructA2, b2 StructB2, c2 StructC2, d2 StructD2, e2 StructE2, f2 StructF1, 101) { 102 a.Equal(a) 103 b.Equal(&b) 104 c.Equal(c) 105 d.Equal(&d) 106 e.Equal(e) 107 f.Equal(&f) 108 109 ap.Equal(*ap) 110 bp.Equal(bp) 111 cp.Equal(*cp) 112 dp.Equal(dp) 113 ep.Equal(*ep) 114 fp.Equal(fp) 115 116 a1.Equal(a1.StructA) 117 b1.Equal(&b1.StructB) 118 c1.Equal(c1) 119 d1.Equal(&d1) 120 e1.Equal(e1) 121 f1.Equal(&f1) 122 123 a2.Equal(*a2.StructA) 124 b2.Equal(b2.StructB) 125 c2.Equal(c2) 126 d2.Equal(&d2) 127 e2.Equal(e2) 128 f2.Equal(&f2) 129} 130 131type ( 132 privateStruct struct{ Public, private int } 133 PublicStruct struct{ Public, private int } 134 ParentStructA struct{ privateStruct } 135 ParentStructB struct{ PublicStruct } 136 ParentStructC struct { 137 privateStruct 138 Public, private int 139 } 140 ParentStructD struct { 141 PublicStruct 142 Public, private int 143 } 144 ParentStructE struct { 145 privateStruct 146 PublicStruct 147 } 148 ParentStructF struct { 149 privateStruct 150 PublicStruct 151 Public, private int 152 } 153 ParentStructG struct { 154 *privateStruct 155 } 156 ParentStructH struct { 157 *PublicStruct 158 } 159 ParentStructI struct { 160 *privateStruct 161 *PublicStruct 162 } 163 ParentStructJ struct { 164 *privateStruct 165 *PublicStruct 166 Public PublicStruct 167 private privateStruct 168 } 169) 170 171func NewParentStructG() *ParentStructG { 172 return &ParentStructG{new(privateStruct)} 173} 174func NewParentStructH() *ParentStructH { 175 return &ParentStructH{new(PublicStruct)} 176} 177func NewParentStructI() *ParentStructI { 178 return &ParentStructI{new(privateStruct), new(PublicStruct)} 179} 180func NewParentStructJ() *ParentStructJ { 181 return &ParentStructJ{ 182 privateStruct: new(privateStruct), PublicStruct: new(PublicStruct), 183 } 184} 185func (s *privateStruct) SetPrivate(i int) { s.private = i } 186func (s *PublicStruct) SetPrivate(i int) { s.private = i } 187func (s *ParentStructC) SetPrivate(i int) { s.private = i } 188func (s *ParentStructD) SetPrivate(i int) { s.private = i } 189func (s *ParentStructF) SetPrivate(i int) { s.private = i } 190func (s *ParentStructA) PrivateStruct() *privateStruct { return &s.privateStruct } 191func (s *ParentStructC) PrivateStruct() *privateStruct { return &s.privateStruct } 192func (s *ParentStructE) PrivateStruct() *privateStruct { return &s.privateStruct } 193func (s *ParentStructF) PrivateStruct() *privateStruct { return &s.privateStruct } 194func (s *ParentStructG) PrivateStruct() *privateStruct { return s.privateStruct } 195func (s *ParentStructI) PrivateStruct() *privateStruct { return s.privateStruct } 196func (s *ParentStructJ) PrivateStruct() *privateStruct { return s.privateStruct } 197func (s *ParentStructJ) Private() *privateStruct { return &s.private } 198