1
0
mirror of https://github.com/golang/go synced 2024-11-20 03:04:40 -07:00

add a test for %+v in nested structures.

threw in an embedded one for good measure.

R=rsc
CC=golang-dev
https://golang.org/cl/157058
This commit is contained in:
Rob Pike 2009-11-17 22:14:34 -08:00
parent 01c2de0c15
commit ea5cc6c021

View File

@ -40,6 +40,20 @@ type A struct {
x []int;
}
type I int
func (i I) String() string { return Sprintf("<%d>", i) }
type B struct {
i I;
j int;
}
type C struct {
i int;
B;
}
var b byte
var fmttests = []fmtTest{
@ -184,6 +198,10 @@ var fmttests = []fmtTest{
fmtTest{"%v", A{1, 2, "a", []int{1, 2}}, `{1 2 a [1 2]}`},
fmtTest{"%+v", A{1, 2, "a", []int{1, 2}}, `{i:1 j:2 s:a x:[1 2]}`},
// +v on structs with Stringable items
fmtTest{"%+v", B{1, 2}, `{i:<1> j:2}`},
fmtTest{"%+v", C{1, B{2, 3}}, `{i:1 B:{i:<2> j:3}}`},
// go syntax
fmtTest{"%#v", A{1, 2, "a", []int{1, 2}}, `fmt_test.A{i:1, j:0x2, s:"a", x:[]int{1, 2}}`},
fmtTest{"%#v", &b, "(*uint8)(PTR)"},