mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
reflect: add support for DeepEqual
The implementation has been mostly copied from the Go reference implementation with some small changes to fit TinyGo. Source: https://github.com/golang/go/blob/77a11c05d6a6f766c75f804ea9b8796f9a9f85a3/src/reflect/deepequal.go In addition, this commit also contains the following: - A set of tests copied from the Go reflect package. - An increased stack size for the riscv-qemu and hifive1-qemu targets (because they otherwise fail to run the tests). Because these targets are only used for testing, this seems fine to me.
This commit is contained in:
committed by
Ron Evans
parent
5866a47e77
commit
335fb71d2f
Vendored
+40
@@ -27,6 +27,9 @@ type (
|
||||
next *linkedList `description:"chain"`
|
||||
foo int
|
||||
}
|
||||
selfref struct {
|
||||
x *selfref
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -326,6 +329,43 @@ func main() {
|
||||
|
||||
println("\nv.Interface() method")
|
||||
testInterfaceMethod()
|
||||
|
||||
// Test reflect.DeepEqual.
|
||||
var selfref1, selfref2 selfref
|
||||
selfref1.x = &selfref1
|
||||
selfref2.x = &selfref2
|
||||
for i, tc := range []struct {
|
||||
v1, v2 interface{}
|
||||
equal bool
|
||||
}{
|
||||
{int(5), int(5), true},
|
||||
{int(3), int(5), false},
|
||||
{int(5), uint(5), false},
|
||||
{struct {
|
||||
a int
|
||||
b string
|
||||
}{3, "x"}, struct {
|
||||
a int
|
||||
b string
|
||||
}{3, "x"}, true},
|
||||
{struct {
|
||||
a int
|
||||
b string
|
||||
}{3, "x"}, struct {
|
||||
a int
|
||||
b string
|
||||
}{3, "y"}, false},
|
||||
{selfref1, selfref2, true},
|
||||
} {
|
||||
result := reflect.DeepEqual(tc.v1, tc.v2)
|
||||
if result != tc.equal {
|
||||
if tc.equal {
|
||||
println("reflect.DeepEqual() test", i, "not equal while it should be")
|
||||
} else {
|
||||
println("reflect.DeepEqual() test", i, "equal while it should not be")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func emptyFunc() {
|
||||
|
||||
Reference in New Issue
Block a user