mirror of
https://github.com/golang/go
synced 2024-11-22 18:24:48 -07:00
nil in DeepEqual
R=r DELTA=13 (5 added, 6 deleted, 2 changed) OCL=34337 CL=34343
This commit is contained in:
parent
107d404378
commit
33be0c6465
@ -378,6 +378,8 @@ var deepEqualTests = []DeepEqualTest {
|
|||||||
DeepEqualTest{ map[int]string{ 1:"one", 2:"txo" }, map[int]string{ 2:"two", 1:"one" }, false },
|
DeepEqualTest{ map[int]string{ 1:"one", 2:"txo" }, map[int]string{ 2:"two", 1:"one" }, false },
|
||||||
DeepEqualTest{ map[int]string{ 1:"one", }, map[int]string{ 2:"two", 1:"one" }, false },
|
DeepEqualTest{ map[int]string{ 1:"one", }, map[int]string{ 2:"two", 1:"one" }, false },
|
||||||
DeepEqualTest{ map[int]string{ 2:"two", 1:"one" }, map[int]string{ 1:"one", }, false },
|
DeepEqualTest{ map[int]string{ 2:"two", 1:"one" }, map[int]string{ 1:"one", }, false },
|
||||||
|
DeepEqualTest{ nil, 1, false },
|
||||||
|
DeepEqualTest{ 1, nil, false },
|
||||||
|
|
||||||
// Mismatched types
|
// Mismatched types
|
||||||
DeepEqualTest{ 1, 1.0, false },
|
DeepEqualTest{ 1, 1.0, false },
|
||||||
|
@ -22,11 +22,8 @@ type visit struct {
|
|||||||
// comparisons that have already been seen, which allows short circuiting on
|
// comparisons that have already been seen, which allows short circuiting on
|
||||||
// recursive types.
|
// recursive types.
|
||||||
func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
|
func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
|
||||||
if v1 == nil {
|
if v1 == nil || v2 == nil {
|
||||||
return v2 == nil
|
return v1 == v2
|
||||||
}
|
|
||||||
if v2 == nil {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if v1.Type() != v2.Type() {
|
if v1.Type() != v2.Type() {
|
||||||
return false;
|
return false;
|
||||||
@ -126,11 +123,11 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
|
|||||||
// but will scan members of arrays, slices, and fields of structs. It correctly
|
// but will scan members of arrays, slices, and fields of structs. It correctly
|
||||||
// handles recursive types.
|
// handles recursive types.
|
||||||
func DeepEqual(a1, a2 interface{}) bool {
|
func DeepEqual(a1, a2 interface{}) bool {
|
||||||
|
if a1 == nil || a2 == nil {
|
||||||
|
return a1 == a2;
|
||||||
|
}
|
||||||
v1 := NewValue(a1);
|
v1 := NewValue(a1);
|
||||||
v2 := NewValue(a2);
|
v2 := NewValue(a2);
|
||||||
if v1 == nil {
|
|
||||||
return v1 == v2;
|
|
||||||
}
|
|
||||||
if v1.Type() != v2.Type() {
|
if v1.Type() != v2.Type() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user