Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
64627b04
Commit
64627b04
authored
Apr 15, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check for type equality in deepequal
R=r,dnadasi DELTA=9 (8 added, 0 deleted, 1 changed) OCL=27473 CL=27486
parent
19692bee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
all_test.go
src/lib/reflect/all_test.go
+4
-1
deepequal.go
src/lib/reflect/deepequal.go
+6
-1
No files found.
src/lib/reflect/all_test.go
View file @
64627b04
...
...
@@ -310,7 +310,7 @@ func TestInterfaceValue(t *testing.T) {
assert
(
v2
.
Type
()
.
String
(),
"interface { }"
);
v3
:=
v2
.
(
reflect
.
InterfaceValue
)
.
Value
();
assert
(
v3
.
Type
()
.
String
(),
"float"
);
i3
:=
v2
.
Interface
();
if
f
,
ok
:=
i3
.
(
float
);
!
ok
{
a
,
typ
,
c
:=
sys
.
Reflect
(
i3
);
...
...
@@ -387,6 +387,8 @@ type Basic struct {
y
float32
}
type
NotBasic
Basic
type
Recursive
struct
{
x
int
;
r
*
Recursive
...
...
@@ -429,6 +431,7 @@ var deepEqualTests = []DeepEqualTest {
DeepEqualTest
{
0.5
,
"hello"
,
false
},
DeepEqualTest
{
[]
int
{
1
,
2
,
3
},
[
3
]
int
{
1
,
2
,
3
},
false
},
DeepEqualTest
{
&
[
3
]
interface
{}
{
1
,
2
,
4
},
&
[
3
]
interface
{}
{
1
,
2
,
"s"
},
false
},
DeepEqualTest
{
Basic
{
1
,
0.5
},
NotBasic
{
1
,
0.5
},
false
},
}
func
TestDeepEqual
(
t
*
testing
.
T
)
{
...
...
src/lib/reflect/deepequal.go
View file @
64627b04
...
...
@@ -74,5 +74,10 @@ func deepValueEqual(v1, v2 Value, visited map[Addr]Addr) bool {
// handles recursive types. Until reflection supports maps, maps are equal iff
// they are identical.
func
DeepEqual
(
a1
,
a2
interface
{})
bool
{
return
deepValueEqual
(
NewValue
(
a1
),
NewValue
(
a2
),
make
(
map
[
Addr
]
Addr
));
v1
:=
NewValue
(
a1
);
v2
:=
NewValue
(
a2
);
if
!
equalType
(
v1
.
Type
(),
v2
.
Type
())
{
return
false
;
}
return
deepValueEqual
(
v1
,
v2
,
make
(
map
[
Addr
]
Addr
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment