LEFT | RIGHT |
1 // Copied with small adaptations from the reflect package in the | 1 // Copied with small adaptations from the reflect package in the |
2 // Go source tree. | 2 // Go source tree. |
3 | 3 |
4 // Copyright 2009 The Go Authors. All rights reserved. | 4 // Copyright 2009 The Go Authors. All rights reserved. |
5 // Use of this source code is governed by a BSD-style | 5 // Use of this source code is governed by a BSD-style |
6 // license that can be found in the LICENSE file. | 6 // license that can be found in the LICENSE file. |
7 | 7 |
8 package checkers | 8 package checkers |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 func DeepEqual(a1, a2 interface{}) (bool, error) { | 220 func DeepEqual(a1, a2 interface{}) (bool, error) { |
221 errorf := func(f string, a ...interface{}) error { | 221 errorf := func(f string, a ...interface{}) error { |
222 return &mismatchError{ | 222 return &mismatchError{ |
223 v1: reflect.ValueOf(a1), | 223 v1: reflect.ValueOf(a1), |
224 v2: reflect.ValueOf(a2), | 224 v2: reflect.ValueOf(a2), |
225 path: "", | 225 path: "", |
226 how: fmt.Sprintf(f, a...), | 226 how: fmt.Sprintf(f, a...), |
227 } | 227 } |
228 } | 228 } |
229 if a1 == nil || a2 == nil { | 229 if a1 == nil || a2 == nil { |
230 » » return a1 == a2, errorf("nil vs non-nil mismatch") | 230 » » if a1 == a2 { |
| 231 » » » return true, nil |
| 232 » » } |
| 233 » » return false, errorf("nil vs non-nil mismatch") |
231 } | 234 } |
232 v1 := reflect.ValueOf(a1) | 235 v1 := reflect.ValueOf(a1) |
233 v2 := reflect.ValueOf(a2) | 236 v2 := reflect.ValueOf(a2) |
234 if v1.Type() != v2.Type() { | 237 if v1.Type() != v2.Type() { |
235 return false, errorf("type mismatch %s vs %s", v1.Type(), v2.Typ
e()) | 238 return false, errorf("type mismatch %s vs %s", v1.Type(), v2.Typ
e()) |
236 } | 239 } |
237 return deepValueEqual("", v1, v2, make(map[visit]bool), 0) | 240 return deepValueEqual("", v1, v2, make(map[visit]bool), 0) |
238 } | 241 } |
239 | 242 |
240 // interfaceOf returns v.Interface() even if v.CanInterface() == false. | 243 // interfaceOf returns v.Interface() even if v.CanInterface() == false. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 A int | 294 A int |
292 } | 295 } |
293 vA := reflect.ValueOf(t).FieldByName("A") | 296 vA := reflect.ValueOf(t).FieldByName("A") |
294 va := reflect.ValueOf(t).FieldByName("a") | 297 va := reflect.ValueOf(t).FieldByName("a") |
295 flagA := *flagField(&vA) | 298 flagA := *flagField(&vA) |
296 flaga := *flagField(&va) | 299 flaga := *flagField(&va) |
297 if flagA&flagRO != 0 || flaga&flagRO == 0 { | 300 if flagA&flagRO != 0 || flaga&flagRO == 0 { |
298 panic("reflect.Value read-only flag has changed value") | 301 panic("reflect.Value read-only flag has changed value") |
299 } | 302 } |
300 } | 303 } |
LEFT | RIGHT |