Add tests for structs with multiple equiv fields.
This commit adds tests for a struct which has an embedded struct pointer and a field that is a pointer to the same object. This ensures the cycle detection is properly reset between fields.
This commit is contained in:
parent
cddf8663bd
commit
f2641d5e6e
|
@ -59,6 +59,17 @@ type indirCir3 struct {
|
||||||
ps1 *indirCir1
|
ps1 *indirCir1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// embed is used to test embedded structures.
|
||||||
|
type embed struct {
|
||||||
|
a string
|
||||||
|
}
|
||||||
|
|
||||||
|
// embedwrap is used to test embedded structures.
|
||||||
|
type embedwrap struct {
|
||||||
|
*embed
|
||||||
|
e *embed
|
||||||
|
}
|
||||||
|
|
||||||
// panicer is used to intentionally cause a panic for testing spew properly
|
// panicer is used to intentionally cause a panic for testing spew properly
|
||||||
// handles them
|
// handles them
|
||||||
type panicer int
|
type panicer int
|
||||||
|
|
|
@ -39,6 +39,7 @@ base test element are also tested to ensure proper indirection across all types.
|
||||||
- Struct that contains another struct
|
- Struct that contains another struct
|
||||||
- Struct that contains custom type with Stringer pointer interface via both
|
- Struct that contains custom type with Stringer pointer interface via both
|
||||||
exported and unexported fields
|
exported and unexported fields
|
||||||
|
- Struct that contains embedded struct and field to same struct
|
||||||
- Uintptr to 0 (null pointer)
|
- Uintptr to 0 (null pointer)
|
||||||
- Uintptr address of real variable
|
- Uintptr address of real variable
|
||||||
- Unsafe.Pointer to 0 (null pointer)
|
- Unsafe.Pointer to 0 (null pointer)
|
||||||
|
@ -542,6 +543,25 @@ func addStructDumpTests() {
|
||||||
addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
|
addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
|
||||||
addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
|
addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
|
||||||
addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
|
addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
|
||||||
|
|
||||||
|
// Struct that contains embedded struct and field to same struct.
|
||||||
|
e := embed{"embedstr"}
|
||||||
|
v4 := embedwrap{embed: &e, e: &e}
|
||||||
|
nv4 := (*embedwrap)(nil)
|
||||||
|
pv4 := &v4
|
||||||
|
eAddr := fmt.Sprintf("%p", &e)
|
||||||
|
v4Addr := fmt.Sprintf("%p", pv4)
|
||||||
|
pv4Addr := fmt.Sprintf("%p", &pv4)
|
||||||
|
v4t := "spew_test.embedwrap"
|
||||||
|
v4t2 := "spew_test.embed"
|
||||||
|
v4t3 := "string"
|
||||||
|
v4s := "{\n embed: (*" + v4t2 + ")(" + eAddr + ")({\n a: (" + v4t3 +
|
||||||
|
") \"embedstr\"\n }),\n e: (*" + v4t2 + ")(" + eAddr + ")({\n" +
|
||||||
|
" a: (" + v4t3 + ") \"embedstr\"\n })\n}"
|
||||||
|
addDumpTest(v4, "("+v4t+") "+v4s+"\n")
|
||||||
|
addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
|
||||||
|
addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
|
||||||
|
addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func addUintptrDumpTests() {
|
func addUintptrDumpTests() {
|
||||||
|
|
|
@ -39,6 +39,7 @@ base test element are also tested to ensure proper indirection across all types.
|
||||||
- Struct that contains another struct
|
- Struct that contains another struct
|
||||||
- Struct that contains custom type with Stringer pointer interface via both
|
- Struct that contains custom type with Stringer pointer interface via both
|
||||||
exported and unexported fields
|
exported and unexported fields
|
||||||
|
- Struct that contains embedded struct and field to same struct
|
||||||
- Uintptr to 0 (null pointer)
|
- Uintptr to 0 (null pointer)
|
||||||
- Uintptr address of real variable
|
- Uintptr address of real variable
|
||||||
- Unsafe.Pointer to 0 (null pointer)
|
- Unsafe.Pointer to 0 (null pointer)
|
||||||
|
@ -915,6 +916,41 @@ func addStructFormatterTests() {
|
||||||
addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s3)
|
addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s3)
|
||||||
addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s3)
|
addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s3)
|
||||||
addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")
|
addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")
|
||||||
|
|
||||||
|
// Struct that contains embedded struct and field to same struct.
|
||||||
|
e := embed{"embedstr"}
|
||||||
|
v4 := embedwrap{embed: &e, e: &e}
|
||||||
|
nv4 := (*embedwrap)(nil)
|
||||||
|
pv4 := &v4
|
||||||
|
eAddr := fmt.Sprintf("%p", &e)
|
||||||
|
v4Addr := fmt.Sprintf("%p", pv4)
|
||||||
|
pv4Addr := fmt.Sprintf("%p", &pv4)
|
||||||
|
v4t := "spew_test.embedwrap"
|
||||||
|
v4t2 := "spew_test.embed"
|
||||||
|
v4t3 := "string"
|
||||||
|
v4s := "{<*>{embedstr} <*>{embedstr}}"
|
||||||
|
v4s2 := "{embed:<*>(" + eAddr + "){a:embedstr} e:<*>(" + eAddr +
|
||||||
|
"){a:embedstr}}"
|
||||||
|
v4s3 := "{embed:(*" + v4t2 + "){a:(" + v4t3 + ")embedstr} e:(*" + v4t2 +
|
||||||
|
"){a:(" + v4t3 + ")embedstr}}"
|
||||||
|
v4s4 := "{embed:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 +
|
||||||
|
")embedstr} e:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + ")embedstr}}"
|
||||||
|
addFormatterTest("%v", v4, v4s)
|
||||||
|
addFormatterTest("%v", pv4, "<*>"+v4s)
|
||||||
|
addFormatterTest("%v", &pv4, "<**>"+v4s)
|
||||||
|
addFormatterTest("%+v", nv4, "<nil>")
|
||||||
|
addFormatterTest("%+v", v4, v4s2)
|
||||||
|
addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s2)
|
||||||
|
addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s2)
|
||||||
|
addFormatterTest("%+v", nv4, "<nil>")
|
||||||
|
addFormatterTest("%#v", v4, "("+v4t+")"+v4s3)
|
||||||
|
addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s3)
|
||||||
|
addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s3)
|
||||||
|
addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")
|
||||||
|
addFormatterTest("%#+v", v4, "("+v4t+")"+v4s4)
|
||||||
|
addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s4)
|
||||||
|
addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s4)
|
||||||
|
addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")
|
||||||
}
|
}
|
||||||
|
|
||||||
func addUintptrFormatterTests() {
|
func addUintptrFormatterTests() {
|
||||||
|
|
Loading…
Reference in New Issue