]> Cypherpunks repositories - gostls13.git/commitdiff
fmt.Printf: write tests for %T.
authorRob Pike <r@golang.org>
Tue, 15 Jun 2010 00:42:31 +0000 (17:42 -0700)
committerRob Pike <r@golang.org>
Tue, 15 Jun 2010 00:42:31 +0000 (17:42 -0700)
Fix a bug that caused it to ignore field widths.

R=rsc
CC=golang-dev
https://golang.org/cl/1704041

src/pkg/fmt/fmt_test.go
src/pkg/fmt/print.go

index d9bb167dd9015bd8dcbc6ae44c8baa7017f62665..e48e874b15c309d4454c821ff522ce87c1ad5a8f 100644 (file)
@@ -314,6 +314,12 @@ var fmttests = []fmtTest{
        fmtTest{"%v", renamedComplex64(3 + 4i), "(3+4i)"},
        fmtTest{"%v", renamedComplex128(4 - 3i), "(4-3i)"},
 
+       // %T
+       fmtTest{"%T", (4 - 3i), "complex"},
+       fmtTest{"%T", renamedComplex128(4 - 3i), "fmt_test.renamedComplex128"},
+       fmtTest{"%T", intVal, "int"},
+       fmtTest{"%6T", &intVal, "  *int"},
+
        // erroneous things
        fmtTest{"%d", "hello", "%d(string=hello)"},
        fmtTest{"no args", "hello", "no args?(extra string=hello)"},
index 31bd1f6f734c1124f4ec2d6e74f145725e48efe0..16ab7195235421bc69139c03582df496818e6beb 100644 (file)
@@ -959,7 +959,7 @@ func (p *pp) doPrintf(format string, a []interface{}) {
                                p.buf.Write(nilAngleBytes)
                                break
                        }
-                       p.buf.WriteString(reflect.Typeof(field).String())
+                       p.printField(reflect.Typeof(field).String(), 's', false, false, 0)
                        continue
                }