Commit ea5cc6c0 authored by Rob Pike's avatar Rob Pike

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
parent 01c2de0c
...@@ -40,6 +40,20 @@ type A struct { ...@@ -40,6 +40,20 @@ type A struct {
x []int; 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 b byte
var fmttests = []fmtTest{ var fmttests = []fmtTest{
...@@ -184,6 +198,10 @@ 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}}, `{1 2 a [1 2]}`},
fmtTest{"%+v", A{1, 2, "a", []int{1, 2}}, `{i:1 j:2 s:a x:[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 // 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", 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)"}, fmtTest{"%#v", &b, "(*uint8)(PTR)"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment